[2.5.1] "UnicodeDecodeError: 'ascii' codec can't decode byte"?

Ulrich Eckhardt eckhardt at satorlaser.com
Wed Oct 29 11:11:38 CET 2008


Gilles Ganault wrote:
> I'm getting this error while downloading and parsing web pages:
> 
> =====
>     title = m.group(1)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position
> 48: ordinal  not in range(128)
> =====
> 
> From what I understand, it's because some strings are Unicode, and
> hence contain characters that are illegal in ASCII.

You just need to use a codec according to the encoding of the webpage. Take
a look at 
  http://wiki.python.org/moin/Python3UnicodeDecodeError
It is about Python 3, but the principles apply nonetheless. In any case,
throwing the error at a websearch will turn up lots of solutions.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list