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

Discussion in 'Python' started by Gilles Ganault, Oct 29, 2008.

  1. Hello

    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.

    Does someone know how to solve this error?

    Thank you.
     
    Gilles Ganault, Oct 29, 2008
    #1
    1. Advertising

  2. 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
     
    Ulrich Eckhardt, Oct 29, 2008
    #2
    1. Advertising

  3. Gilles Ganault

    Steve Holden Guest

    Ulrich Eckhardt wrote:
    > 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.
    >

    I won't believe that statement is producing the error until I see a
    traceback. As far as I'm aware the re module can handle Unicode. Getting
    a UnicodeDecodeError in an assignment would be unusual to say the least.
    Though it's not, I suppose, impossible that calling the .group() method
    of a match object might, it seems unlikely.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Oct 29, 2008
    #3
  4. Gilles Ganault

    Steve Holden Guest

    Ulrich Eckhardt wrote:
    > 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.
    >

    I won't believe that statement is producing the error until I see a
    traceback. As far as I'm aware the re module can handle Unicode. Getting
    a UnicodeDecodeError in an assignment would be unusual to say the least.
    Though it's not, I suppose, impossible that calling the .group() method
    of a match object might, it seems unlikely.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Oct 29, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Siebler
    Replies:
    4
    Views:
    27,474
    Tim Peters
    Oct 8, 2004
  2. Gilles Ganault
    Replies:
    2
    Views:
    1,164
    Gilles Ganault
    Jun 17, 2008
  3. Gabriel Genellina
    Replies:
    0
    Views:
    784
    Gabriel Genellina
    Oct 21, 2008
  4. Tim Golden
    Replies:
    0
    Views:
    136
    Tim Golden
    Nov 27, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    93
    Terry Reedy
    Nov 27, 2013
Loading...

Share This Page