How to get Python to default to UTF8

weheh weheh at verizon.net
Sat Dec 22 03:51:19 EST 2007


Hi Fredrik, thanks for responding. After reading up some more on this, I 
think my title should be changed to "How to get Python to default to ASCII". 
In point of fact, I want my 2 environments to agree so that I can debug 
thinkgs more easily. Right now it's a nightmare.

As to your questions, in this example, I believe the exception was caused by 
trying to do a count of the number of times a string appears in an array. 
One of the strings was unicode and the other was encoded by Python by 
default.




"Fredrik Lundh" <fredrik at pythonware.com> wrote in message 
news:mailman.2678.1198306212.13605.python-list at python.org...
> weheh wrote:
>
>> 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
>
> Could be that sys.stdin.encoding differs between the setups.
>
> *Where* do you get this exception?  In the database layer?  When the 
> script is trying to read things from a file?  When it's trying to output 
> things?  Somewhere else?
>
> </F>
> 





More information about the Python-list mailing list