Unicode error in wx_gdi ?

E

Erik Bethke

Hello All,

I still shaking out my last few bugs in my tile matching game:

I am now down to one stumper for me:
1) when I initialize wxPython
2) from an exe that I have created with py2exe
3) when the executable is located on the desktop as opposed to
somewhere on C or D directly
4) when My Desktop is not written in ascii but instead Korean hangul

I get this error:

Traceback (most recent call last):
File "shanghai.py", line 13, in ?
File "wxPython\__init__.pyc", line 10, in ?
File "wxPython\_wx.pyc", line 3, in ?
File "wxPython\_core.pyc", line 15, in ?
File "wx\__init__.pyc", line 42, in ?
File "wx\_core.pyc", line 10994, in ?
File "wx\_gdi.pyc", line 2443, in ?
File "wx\_gdi.pyc", line 2340, in Locale_AddCatalogLookupPathPrefix
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbf in position
26: ordinal not in range(128)

Granted this may seem like an obscure error, but the net effect is that
I cannot use wxPython for my games and applications as many of my users
will place the executable directly on their desktop and the path of the
desktop contains non-ascii paths.

What do i do from here? Do I go into wx_gdi.py and fix it so that it
uses unicode instead of ascii? I have not yet made any changes to
other people's libraries...

Any help would be much appreciated,
-Erik
 
S

Serge Orlov

Erik said:
Hello All,

I still shaking out my last few bugs in my tile matching game:

I am now down to one stumper for me:
1) when I initialize wxPython
2) from an exe that I have created with py2exe
3) when the executable is located on the desktop as opposed to
somewhere on C or D directly
4) when My Desktop is not written in ascii but instead Korean hangul

I get this error:

Traceback (most recent call last):
File "shanghai.py", line 13, in ?
File "wxPython\__init__.pyc", line 10, in ?
File "wxPython\_wx.pyc", line 3, in ?
File "wxPython\_core.pyc", line 15, in ?
File "wx\__init__.pyc", line 42, in ?
File "wx\_core.pyc", line 10994, in ?
File "wx\_gdi.pyc", line 2443, in ?
File "wx\_gdi.pyc", line 2340, in Locale_AddCatalogLookupPathPrefix
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbf in position
26: ordinal not in range(128)

Granted this may seem like an obscure error,

Thanks to your explanation, it doesn't look very obscure. I think
the code in wxpython either uses sys.path[0] or __file__. Python
still keeps byte strings in there because of backward compatibility.

What do i do from here? Do I go into wx_gdi.py and fix it so that it
uses unicode instead of ascii? I have not yet made any changes to
other people's libraries...

You should contact wxpython people for proper cross platform fix,
meanwhile you can fix that particular error on windows
by changing sys.path[0] into
sys.path[0].decode(sys.getfilesystemencoding())
or do the same thing for __file__. If there are a lot of similar
problems, you can call sys.setdefaultencoding('mbcs') at the start of
your program as last resort. Don't tell anyone I suggested that :)
and remember that sys.setdefaultencoding is removed in site.py,
changing default encoding can mask encoding bugs and make those
bugs hard to trace.

Serge.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top