Trouble Encoding

Kent Johnson kent37 at tds.net
Tue Jun 7 20:44:43 EDT 2005


John Roth wrote:
> <fingermark at gmail.com> wrote in message 
> news:1118135690.961381.207490 at o13g2000cwo.googlegroups.com...
> 
>> I'm using feedparser to parse the following:
>>
>> <div class="indent text">Adv: Termite Inspections! Jenny Moyer welcomes
>> you to her HomeFinderResource.com TM A "MUST See &hellip;</div>
>>
>> I'm receiveing the following error when i try to print the feedparser
>> parsing of the above text:
>>
>> UnicodeEncodeError: 'latin-1' codec can't encode character u'\u201c' in
>> position 86: ordinal not in range(256)
>>
>> Why is this happening and where does the problem lie?
> 
> 
> Several different things are going on here. First, when you try to
> print a unicode string using str() or a similar function, Python is 
> going to
> use the default encoding to render it. The default encoding is usually
> ASCII-7. Why it's trying to use Latin-1 in this case is somewhat
> of a mystery.

Actually I believe it will use sys.stdout.encoding for this, which is presumably latin-1 on fingermark's machine.

Kent



More information about the Python-list mailing list