regards
Steve
On 9/29/2010 1:05 PM, werefr0g wrote:
> Hi,
>
> You should check that your file is actually utf-8 encoded and add the
> folliwing right after shebang:
> # -*- coding: utf-8 -*-
>
> Le 29/09/2010 18:59, jean polo a �crit :
>> Hi.
>> I get an 'UnicodeEncodeError' if I upload a file (ImageField) with non-
>> ascii chars in my application (django-1.2.1).
>>
>> I added:
>>
>> export LANG='en_US.UTF-8'
>> export LC_ALL='en_US.UTF-8'
>>
>> in my /etc/apache2/envvars as stated here:
>> http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror
>>
>> but I still have the same error (after restarting apache).
>> Any hint much appreciated.
>>
>> cheers,
>> _y
>>
>> ps:
>>
>> Traceback (most recent call last):
>> [snip]
>> File "/usr/languages/python/2.6/lib/python2.6/genericpath.py", line
>> 18, in exists
>> st = os.stat(path)
>>
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in
>> position 53: ordinal not in range(128)
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
--
DjangoCon US 2010 September 7-9 http://djangocon.us/
> I have a basic 'Bien' class and a *very basic* 'Image' class (with a
> ForeignKey to Bien).
> BienAdmin has a ImageInline and that's all.
Not even tangentially related, but...
"Do people in non-English-speaking countries code in English?"
http://programmers.stackexchange.com/questions/1483/do-people-in-non-english-speaking-countries-code-in-english
http://www.reddit.com/r/programming/comments/dg5jo/do_people_in_nonenglishspeaking_countries_code_in/
Also, check your database encoding. Somehow you are requiring Django to
convert a Unicode string in to an ASCII string.
regards
Steve
Hi.
I get an 'UnicodeEncodeError' if I upload a file (ImageField) with non-
ascii chars in my application (django-1.2.1).
I added:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
in my /etc/apache2/envvars as stated here:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror
but I still have the same error (after restarting apache).
Any hint much appreciated.
Sorry, sorry.... I proposed Jean to send me the actual file to check its encoding. I asked for his OS too in order to see what editor are available and how it allows to "transcode" the text.
I had a similar problem in a python script. Not necessary to rename files :)
The problem is that when you print a debug statement or write to a file, you
need to specify the correct encoding.
I'll add a snippet of the logger class that i'm using so you'll have an idea.
Also, play with the shell and see if you can reproduce and solve the problem there.
try:
# If the message is unicode, convert to bytecode
screen_message = message
file_message = message
if ( isunicode(message) ):
screen_message = message.encode("cp850")
file_message = (message + '\n').encode("utf-8")
# Print to screen
if ( to_screen == 1 ): print screen_message
# Write to file
f = open(logfile, 'a')
f.write(file_message)
f.close()
except Exception, e:
print "Logmessage: exception %s" % str(e)
I seem to remember that on my windows, the code page in the command screen (cp850)
is different from the code page used in a file (latin1).
Anyway, as you can see, before i print a message to the cmd screen, i encode it.
Same happens when i save the message in the logfile. I encode it to a different
code page however.
You'll have to do the same with other strings that get printed.
This works for me
Regards,
Benedict