[python-win32] Exception when manipulating paths containing non-ASCII characters

skip at pobox.com skip at pobox.com
Fri Aug 28 13:04:10 CEST 2009


I have zero Windows programming experience and also no experience
manipulating paths containing non-ASCII characters.  A Windows user of Task
Coach (which uses the lockfile module) is getting a traceback in this code:

     self.unique_name = os.path.join(dirname,
                                            "%s.%s%s" % (self.hostname,
                                                         tname,
                                                         self.pid))

raising a UnicodeDecodeError:

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 3: ordinal not in range(128)

on a WIndows system when the hostname contains non-ASCII data.  (All the
other elements involved in the os.path.join call are ASCII or numbers.)

I can't reproduce this on my Mac in the obvious way:

    >>> h = u'\u00ef'
    >>> n = "abc"
    >>> p = 123
    >>> os.path.join("c:/temp", "%s.%s.%s" % (h, n, p))
    u'c:/temp/\xef.abc.123'

so I don't know how to fix what appears not to be broke or how to test it
once I do.  I tried the above code snippet on my Mac using a number of
different versions, including CVS trunk, Python 2.5.4 and 2.4.5 from
MacPorts and Apple's /usr/bin/python (2.5.1).  All worked just fine.

The full text of the problem is in the nascent lockfile issue tracker on
bitbucket:

    http://bitbucket.org/smontanaro/lockfile/issue/1/

Frank Niessink, the author of Task Coach, who reported the problem, seems
not to be able to reproduce it in his Windows environment either, though in
further exchanges with his user Frank reported that if she changed the name
of her computer to not contain accented characters lockfile worked for her.
Task Coach comes with an embedded copy of Python 2.5.1.  Can anyone here
shed some light on what the problem might be?

Thanks,

-- 
Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/
    Getting old sucks, but it beats dying young


More information about the python-win32 mailing list