Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField [RSS Feed]

#1 June 12, 2010 16:06:41

Bjørn H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


Hi

Try and put "# -*- encoding: utf-8 -*-#" in the top of the py script.

These danish characters really are a pain the ass.

Regards

Bjørn

On 12 Jun., 14:37, MIL <needb...@gmail.com> wrote:
> I experience problem with special chars like æøå in filename when
> using models.ImageField.
>
> What am I doing wrong?
>
> models.py
>    picture = models.ImageField(upload_to='pics', blank=True,
> verbose_name='Picture of you')
>
> Using model forms
>
> Let say I want to upload picture named "æøå.jpg"
>
> If I do that, I get the following error msg:
> 'ascii' codec can't encode characters in position 59-61: ordinal not
> in range(128)
>
> Django ver 1.2 Alpha
>
> Please help me thanks

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 12, 2010 23:25:31

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


Hi Bjørn

I have allready # -*- encoding: utf-8 -*-# in top of my settings.py
and models.py

Should I put it in all my .py files?

Thanks :o)


On 12 Jun., 17:06, Bjørn Høj Jakobsen <bhjakob...@gmail.com> wrote:
> Hi
>
> Try and put "# -*- encoding: utf-8 -*-#" in the top of the py script.
>
> These danish characters really are a pain the ass.
>
> Regards
>
> Bjørn
>
> On 12 Jun., 14:37, MIL <needb...@gmail.com> wrote:
>
> > I experience problem with special chars like æøå in filename when
> > using models.ImageField.
>
> > What am I doing wrong?
>
> > models.py
> >    picture = models.ImageField(upload_to='pics', blank=True,
> > verbose_name='Picture of you')
>
> > Using model forms
>
> > Let say I want to upload picture named "æøå.jpg"
>
> > If I do that, I get the following error msg:
> > 'ascii' codec can't encode characters in position 59-61: ordinal not
> > in range(128)
>
> > Django ver 1.2 Alpha
>
> > Please help me thanks
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 13, 2010 00:39:15

Alexander J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


did you tried so:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

or something similar?

On Sun, Jun 13, 2010 at 1:25 AM, MichaleHjulskov <needb...@gmail.com> wrote:

> Hi Bjørn
>
> I have allready # -*- encoding: utf-8 -*-# in top of my settings.py
> and models.py
>
> Should I put it in all my .py files?
>
> Thanks :o)
>
>
> On 12 Jun., 17:06, Bjørn Høj Jakobsen <bhjakob...@gmail.com> wrote:
> > Hi
> >
> > Try and put "# -*- encoding: utf-8 -*-#" in the top of the py script.
> >
> > These danish characters really are a pain the ass.
> >
> > Regards
> >
> > Bjørn
> >
> > On 12 Jun., 14:37, MIL <needb...@gmail.com> wrote:
> >
> > > I experience problem with special chars like æøå in filename when
> > > using models.ImageField.
> >
> > > What am I doing wrong?
> >
> > > models.py
> > > picture = models.ImageField(upload_to='pics', blank=True,
> > > verbose_name='Picture of you')
> >
> > > Using model forms
> >
> > > Let say I want to upload picture named "æøå.jpg"
> >
> > > If I do that, I get the following error msg:
> > > 'ascii' codec can't encode characters in position 59-61: ordinal not
> > > in range(128)
> >
> > > Django ver 1.2 Alpha
> >
> > > Please help me thanks
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 13, 2010 00:47:49

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


On Sat, Jun 12, 2010 at 8:37 AM, MIL <needb...@gmail.com> wrote:

> I experience problem with special chars like æøå in filename when
> using models.ImageField.
>
> What am I doing wrong?
>
> models.py
> picture = models.ImageField(upload_to='pics', blank=True,
> verbose_name='Picture of you')
>
> Using model forms
>
> Let say I want to upload picture named "æøå.jpg"
>
> If I do that, I get the following error msg:
> 'ascii' codec can't encode characters in position 59-61: ordinal not
> in range(128)
>
> Django ver 1.2 Alpha
>
>
The full traceback instead of just the error message would help people help
you. Perhaps try this:http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror.
Though that is in with the mod_python doc, it is not a mod_python specific
problem. In general, no matter what deployment environment, your environment
must be set to allow unicode to be passed to file functions, if you want to
be able to manipulate files that contain non-ASCII characters.

Also, you should really update to a 1.2 release level. Why are you running
alpha?

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 June 13, 2010 23:18:54

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


Hi Karen, I did not know there was a new release, sorry.

So if I just install the new release, it will solve the problem just
like that?
Or do I still need to do something, in order to make it work with
special chars in the filenames?

Thanks :o)

Michael



On 13 Jun., 01:47, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sat, Jun 12, 2010 at 8:37 AM, MIL <needb...@gmail.com> wrote:
> > I experience problem with special chars like æøå in filename when
> > using models.ImageField.
>
> > What am I doing wrong?
>
> > models.py
> >   picture = models.ImageField(upload_to='pics', blank=True,
> > verbose_name='Picture of you')
>
> > Using model forms
>
> > Let say I want to upload picture named "æøå.jpg"
>
> > If I do that, I get the following error msg:
> > 'ascii' codec can't encode characters in position 59-61: ordinal not
> > in range(128)
>
> > Django ver 1.2 Alpha
>
> The full traceback instead of just the error message would help people help
> you. Perhaps try
> this:http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/#if-y....
> Though that is in with the mod_python doc, it is not a mod_python specific
> problem. In general, no matter what deployment environment, your environment
> must be set to allow unicode to be passed to file functions, if you want to
> be able to manipulate files that contain non-ASCII characters.
>
> Also, you should really update to a 1.2 release level. Why are you running
> alpha?
>
> Karen
> --http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 June 13, 2010 23:22:18

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


Hi Alexander

No I havent tried that.
What does it do?
Im a little newbie in python, so its a little tricky for me to
understand. Sorry

Michael


On 13 Jun., 01:39, Alexander Jeliuc <jeliucalexa...@gmail.com> wrote:
> did you tried so:
>
> import sys
> reload(sys)
> sys.setdefaultencoding('utf-8')
>
> or something similar?
>
> On Sun, Jun 13, 2010 at 1:25 AM, MichaleHjulskov <needb...@gmail.com> wrote:
> > Hi Bjørn
>
> > I have allready # -*- encoding: utf-8 -*-# in top of my settings.py
> > and models.py
>
> > Should I put it in all my .py files?
>
> > Thanks :o)
>
> > On 12 Jun., 17:06, Bjørn Høj Jakobsen <bhjakob...@gmail.com> wrote:
> > > Hi
>
> > > Try and put "# -*- encoding: utf-8 -*-#" in the top of the py script.
>
> > > These danish characters really are a pain the ass.
>
> > > Regards
>
> > > Bjørn
>
> > > On 12 Jun., 14:37, MIL <needb...@gmail.com> wrote:
>
> > > > I experience problem with special chars like æøå in filename when
> > > > using models.ImageField.
>
> > > > What am I doing wrong?
>
> > > > models.py
> > > >    picture = models.ImageField(upload_to='pics', blank=True,
> > > > verbose_name='Picture of you')
>
> > > > Using model forms
>
> > > > Let say I want to upload picture named "æøå.jpg"
>
> > > > If I do that, I get the following error msg:
> > > > 'ascii' codec can't encode characters in position 59-61: ordinal not
> > > > in range(128)
>
> > > > Django ver 1.2 Alpha
>
> > > > Please help me thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 June 13, 2010 23:24:24

Alexander J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


It also depends on your filesystem i think

On Mon, Jun 14, 2010 at 1:18 AM, MichaleHjulskov <needb...@gmail.com> wrote:

> Hi Karen, I did not know there was a new release, sorry.
>
> So if I just install the new release, it will solve the problem just
> like that?
> Or do I still need to do something, in order to make it work with
> special chars in the filenames?
>
> Thanks :o)
>
> Michael
>
>
>
> On 13 Jun., 01:47, Karen Tracey <kmtra...@gmail.com> wrote:
> > On Sat, Jun 12, 2010 at 8:37 AM, MIL <needb...@gmail.com> wrote:
> > > I experience problem with special chars like æøå in filename when
> > > using models.ImageField.
> >
> > > What am I doing wrong?
> >
> > > models.py
> > > picture = models.ImageField(upload_to='pics', blank=True,
> > > verbose_name='Picture of you')
> >
> > > Using model forms
> >
> > > Let say I want to upload picture named "æøå.jpg"
> >
> > > If I do that, I get the following error msg:
> > > 'ascii' codec can't encode characters in position 59-61: ordinal not
> > > in range(128)
> >
> > > Django ver 1.2 Alpha
> >
> > The full traceback instead of just the error message would help people
> help
> > you. Perhaps try this:
>http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/#if-y....
> > Though that is in with the mod_python doc, it is not a mod_python
> specific
> > problem. In general, no matter what deployment environment, your
> environment
> > must be set to allow unicode to be passed to file functions, if you want
> to
> > be able to manipulate files that contain non-ASCII characters.
> >
> > Also, you should really update to a 1.2 release level. Why are you
> running
> > alpha?
> >
> > Karen
> > --http://tracey.org/kmt/>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 June 13, 2010 23:28:15

Alexander J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


reload(sys) etc you can put it in start of your settings.py it will reload
python utf-8 support so you will able to use different i had such problem
executing spain/portugal project

import os, sys
reload(sys)
sys.setdefaultencoding( "utf-8" )


On Mon, Jun 14, 2010 at 1:24 AM, Alexander Jeliuc
<jeliucalexa...@gmail.com>wrote:

> It also depends on your filesystem i think
>
>
> On Mon, Jun 14, 2010 at 1:18 AM, MichaleHjulskov <needb...@gmail.com>wrote:
>
>> Hi Karen, I did not know there was a new release, sorry.
>>
>> So if I just install the new release, it will solve the problem just
>> like that?
>> Or do I still need to do something, in order to make it work with
>> special chars in the filenames?
>>
>> Thanks :o)
>>
>> Michael
>>
>>
>>
>> On 13 Jun., 01:47, Karen Tracey <kmtra...@gmail.com> wrote:
>> > On Sat, Jun 12, 2010 at 8:37 AM, MIL <needb...@gmail.com> wrote:
>> > > I experience problem with special chars like æøå in filename when
>> > > using models.ImageField.
>> >
>> > > What am I doing wrong?
>> >
>> > > models.py
>> > > picture = models.ImageField(upload_to='pics', blank=True,
>> > > verbose_name='Picture of you')
>> >
>> > > Using model forms
>> >
>> > > Let say I want to upload picture named "æøå.jpg"
>> >
>> > > If I do that, I get the following error msg:
>> > > 'ascii' codec can't encode characters in position 59-61: ordinal not
>> > > in range(128)
>> >
>> > > Django ver 1.2 Alpha
>> >
>> > The full traceback instead of just the error message would help people
>> help
>> > you. Perhaps try this:
>>http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/#if-y....
>> > Though that is in with the mod_python doc, it is not a mod_python
>> specific
>> > problem. In general, no matter what deployment environment, your
>> environment
>> > must be set to allow unicode to be passed to file functions, if you want
>> to
>> > be able to manipulate files that contain non-ASCII characters.
>> >
>> > Also, you should really update to a 1.2 release level. Why are you
>> running
>> > alpha?
>> >
>> > Karen
>> > --http://tracey.org/kmt/>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>>
>>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#9 June 14, 2010 00:22:19

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


On Sun, Jun 13, 2010 at 6:18 PM, MichaleHjulskov <needb...@gmail.com> wrote:

> Hi Karen, I did not know there was a new release, sorry.
>
> So if I just install the new release, it will solve the problem just
> like that?
> Or do I still need to do something, in order to make it work with
> special chars in the filenames?
>
>
No, with the current release you still need to ensure your environment is
set properly to allow Django to pass unicode to file system functions. The
behavior I am guessing you are seeing (absent the full traceback to be sure)
is not a bug in Django, it's an error in your environment setup. I pointed
to the place in the doc where this is mentioned, and where some details of
properly setting things up for Apache is covered, in the first paragraph of
my first response.

I just mentioned upgrading from the alpha level of code because there are
plenty of bugs that were fixed between alpha and release, and your life will
likely be easier if you use release level code instead of alpha.

Karen

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#10 June 14, 2010 03:55:36

S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField


Hello,

Are you using MySQL and what is the collation of your database. I am
running 1.2.1 and encountering similar problems.

My issue involves utf8_bin collation on mysql 5.1.41-3ubuntu12.3. The
issue is thus: I create a model with an ImageField and save a new
instance to my utf8_bin collated mysql backend. This instance has a
file associated with non-ascii characters in it, e.g.
"Sinéad_OConnor.jpg". Next I attempt delete the file (via the admin)
and I get a:

'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in
range(128)

FYI, MySQLdb does not return unicode strings with a utf8_bin collation
set.
for a brief description of that issue see:http://code.djangoproject.com/ticket/8340#comment:4The traceback from my exception reveals the exception being thrown in
"django/db/models/fields/files.py" in get_prep_value (line 248).
FileField is a subclass of Field, but implements the same backend
MySQL type (varchar) as a CharField. However it seems that FileField
and CharField have completely different implementations of
get_prep_db.

Here is CharField's implementation:
def to_python(self, value):
if isinstance(value, basestring) or value is None:
return value
return smart_unicode(value)

def get_prep_value(self, value):
return self.to_python(value)

Here is Filefield's:
def get_prep_value(self, value):
"Returns field's value prepared for saving into a database."
# Need to convert File objects provided via a form to unicode
for database insertion
if value is None:
return None
return unicode(value)

My experimentations revealed that if I replace the FileField
implementation of get_prep_value with the CharField, the exception
goes away. The issue is that the default encoding is ascii and so
unicode() called on a utf8 byte str blows up. The CharField
implementation simply checks if the value is an instance of basestring
and just passes it through. This latter approach seems better to me.
As it stands, I'm inclined to think this issue is a bug.

Thanks much,
-Sam





On Jun 13, 6:22 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Jun 13, 2010 at 6:18 PM, MichaleHjulskov <needb...@gmail.com> wrote:
> > Hi Karen, I did not know there was a new release, sorry.
>
> > So if I just install the new release, it will solve the problem just
> > like that?
> > Or do I still need to do something, in order to make it work with
> > special chars in the filenames?
>
> No, with the current release you still need to ensure your environment is
> set properly to allow Django to pass unicode to file system functions. The
> behavior I am guessing you are seeing (absent the full traceback to be sure)
> is not a bug in Django, it's an error in your environment setup. I pointed
> to the place in the doc where this is mentioned, and where some details of
> properly setting things up for Apache is covered, in the first paragraph of
> my first response.
>
> I just mentioned upgrading from the alpha level of code because there are
> plenty of bugs that were fixed between alpha and release, and your life will
> likely be easier if you use release level code instead of alpha.
>
> Karen

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support