[Tutor] UnicodeDecodeError

Michael Lange klappnase at freenet.de
Wed Feb 23 13:05:58 CET 2005


On Tue, 22 Feb 2005 19:17:40 -0500
"Isr Gish" <isrgish at fastem.com> wrote:

 
> This part of the error is saying what the problem is.
> 
>    >UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 22: ordinal not in range(128)
>   
> Thatthe ascii codec that's being used can't decode any ascii code above 128. And the code 0xe4 is higher then that.
> You would have to use a different encoding, like msbc.
> If i remmeber correctly you should do something like the following.
> 
> self.nextfile = self.nextfile.encode('msbc')
> Then it should work.
> 
> If it doesn't work try posting what error you get.
> 
> All the best
> Irr 
> 
> 
Thanks for the reply,

it looks to me however that the problem is rather the gettext part; once I discovered this problem
I can produce similar errors at other points in my app that *seem* to only occur when a gettext string
gets combined with a string that is returned by user input from some Tkinter widget. The final
complaint in the traceback is always about a (german) special character in the translated gettext string:

##############################################################################
UnicodeDecodeError Exception in Tk callback
  Function: <function <lambda> at 0xb72ec304> (type: <type 'function'>)
  Args: ()
Traceback (innermost last):
  File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwBase.py", line 1747, in __call__
    return apply(self.func, args)
  File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwDialog.py", line 153, in <lambda>
    command=lambda self=self, name=name: self._doCommand(name))
  File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwDialog.py", line 132, in _doCommand
    return command(name)
  File "/usr/local/share/phonoripper-0.6.2/widgets/FileSelectDialog.py", line 206, in go
    if not self.ok():
  File "/usr/local/share/phonoripper-0.6.2/widgets/FileSelectDialog.py", line 201, in ok
    return self.fo_handler.create_ok(self.full_path)
  File "/usr/local/share/phonoripper-0.6.2/FileOperationHandler.py", line 43, in create_ok
    message=_('File already exists:\n"%s"\nDo you want to overwrite it?') % filename)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 19: ordinal not in range(128)

##############################################################################

The german translation of 'File already exists:\n"%s"\nDo you want to overwrite it?' contains a special
character ('\xfc'), filename is of course simply the complete path to a file as it is returned by a "Save as..."
dialog box. I get this error for some reason if I choose '\xe4.wav' as basename for "filename" but not
if I choose 'A\xe4.wav' . Like I said in my first post, there are no errors if I remove the german .mo file,
so gettext uses the english strings. 

What seems really weird to me here is that it looks like both the translated gettext string and the special
characters in my "filename" variable *can* be decoded, but not both at a time - but only under (rare) circumstances
( setting "filename" to "/somepath/A\xe4.wav" works but "/somepath/\xe4.wav" not).

I'm really lost here, so any further hints are very appreciated.

Thanks and best regards

Michael



More information about the Tutor mailing list