How to get Python to default to UTF8

weheh weheh at verizon.net
Fri Dec 21 23:44:07 EST 2007


I'm developing a cgi-bin application that must be unicode sensitive. I'm 
striving for a UTF8 implementation. I'm running python 2.3 on a development 
machine (windows xp) and a server (windows xp server). Both environments are 
running Apache 2.2 with the same configuration file.

The problem is this. On my development machine I get the following unicode 
error:

UnicodeDecodeError: 'utf8' codec can't decode bytes in position 4-6: invalid 
data
args = ('utf8', 'adem\xe3\xa1s', 4, 7, 'invalid data')
encoding = 'utf8'
end = 7
object = 'adem\xe3\xa1s'
reason = 'invalid data'
start = 4


On my server, running exactly the same python code, I see the following 
unicode error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 4: 
ordinal not in range(128)
args = ('ascii', 'adem\xe3\xa1s', 4, 5, 'ordinal not in range(128)')
encoding = 'ascii'
end = 5
object = 'adem\xe3\xa1s'
reason = 'ordinal not in range(128)'
start = 4

Note the differences in the encoding -- on the development machine it's utf8 
but on the server it's ascii.

I was under the impression that Python assumed ascii encoding by default. 
I'm wondering how did my development machine get to be utf8? And since my 
python code is the same on both machines, what is it about my configuration 
that could be causing a difference in default encoding? I checked site.py on 
both machines and both files default to ASCII, so I assume it's something 
else.

Thanks in advance. 





More information about the Python-list mailing list