Re: UnicodeDecodeError

Werner Fleck <[email protected]>
Newsgroups gmane.mail.spam.tmda.user
Message-ID <[email protected]>
This one was harder since the error doesn't show up when using python 
2.4, so I had to go back to 2.3 to reproduce it.

Attached to this message is a diff which gives me no errors, neither 
with 2.3 nor with 2.4. But there is a slight difference: using python2.3 
  the pending messages display shows the charset, using 2.4 it doesn't. 
I have attached screen captures of both.

Werner

Adam Todd schrieb:
> 
>          # Mark it and use the fallback
>          else:
> # 20061118-at ref tmda-users list
> #          return "(%s) %s" % (CharSet,
> #            TranslateToUTF8(PVars[("General", "CSEncoding")], Str, Errors))
> 
>           return TranslateToUTF8(PVars[("General", "CSEncoding")],
>             "(%s) %s" % (CharSet, unicode(Str, "latin1")), Errors)
> 
>          Decoder = Lib.Codec().decode
>        except ImportError:
> 
> 
> OK, did that.
> 
> And the first Pending page came up fine.  But going to the next one:
> 
>   /common/app/tmda-cgi-0.15/Unicode.py in 
> TranslateToUTF8(CharSet=u'iso-2022-jp', 
> Str='\x96\x88\x93\xfa\x82\xbd\x82\xa2\x82\xad\x82\xc2\x82\xc8\x82\xcc\x82\xc5', 
> Errors='ignore')
>    112       except ImportError:
>    113         # We know what it was, but we don't have the library installed.
>    114         return "(%s) %s" % (CharSet, Str)
>    115
>    116   # Decode string to Unicode
> CharSet = u'iso-2022-jp', Str = 
> '\x96\x88\x93\xfa\x82\xbd\x82\xa2\x82\xad\x82\xc2\x82\xc8\x82\xcc\x82\xc5'
> 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 0: 
> ordinal not in range(128)
>        args = ('ascii', 
> '\x96\x88\x93\xfa\x82\xbd\x82\xa2\x82\xad\x82\xc2\x82\xc8\x82\xcc\x82\xc5', 
> 0, 1, 'ordinal not in range(128)')
>        encoding = 'ascii'
>        end = 1
>        object = 
> '\x96\x88\x93\xfa\x82\xbd\x82\xa2\x82\xad\x82\xc2\x82\xc8\x82\xcc\x82\xc5'
>        reason = 'ordinal not in range(128)'
>        start = 0
> 
> 
> I still reckon "ditch it!"  /dev/null is a nice place, I'm hardly going to 
> be able to read it anyway!  (Yes, again I'm evil!)
> 
> 
> 
> At 12:11 AM 18/11/2006, Jim Ramsay wrote:
>> Werner Fleck <[email protected]> wrote:
>>> I might have found a fix for the problem, but be aware that this is my
>>> first try at programming python :-)
>>>
>>> The error seems to be caused by the string operation in the line
>>>
>>>     return "(%s) %s" % (CharSet,
>>>       TranslateToUTF8(PVars[("General", "CSEncoding")], Str, Errors))
>>>
>>> When I replace this with
>>>
>>>     return TranslateToUTF8(PVars[("General", "CSEncoding")],
>>>       "(%s) %s" % (CharSet, unicode(Str, "latin1")),
>>>       Errors)
>>>
>>> everything works fine for me.
>>>
>>> I've attached a diff to this message.
>> Great, and thanks for this!  Adam, could you please try this patch and
>> let me know if it fixes things for you?  If so, I'll check it in to CVS
>> right away.
>>
>> --
>> Jim Ramsay
>> "Me fail English?  That's unpossible!"
>>
>> _____________________________________________
>> tmda-users mailing list ([email protected])
>> http://tmda.net/lists/listinfo/tmda-users
>
Unicode.py.diff.gz (application/gzip, 555 B) - not displayed
Pending E-mail Python 2.3.bmp (image/bmp, 127.6 KB) - not displayed
Pending E-mail Python 2.4.bmp (image/bmp, 123.6 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.