Skip,
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.)
>
A quite common pain within the non-ASCII-World of Python on Windows
programming.
The quickest soliution I found is to switch the sys.setdefaultencoding to
UTF-8, follower on slot 2 is to switch default-encoding to latin-1.
Both solutions are productive in real world projects for 5 (utf-8) and 9
years (latin-1) with various apps by me; and a similiar solution is reported
by Chris Withers for running productive for 5 years.
Both solutions were called being highly dangerous by MvL and others on
c.p.dev; esp. pointing out problems that can happen concerning hashes /
dict-keys not comparing as expected.
A more work-intensive soluton: only use unicode inside your application and
have a dedicated encoding step when interfacing with the environment (the
MAL recommend way, find slides here:
http://www.egenix.com/library/presentations/#DesigningUnicodeAwareApplicationsInPython
)
one try in that step: make that string-substituion a unicode substitution.
(guessing that self.hostname is Unicode not String on winnt and up)
self.unique_name = os.path.join(dirname,
u"%s.%s%s" % (self.hostname,
tname,
self.pid))
(ATM converting my code step-by-step to that "only use unicode inside" way,
with having a sys.defaultencoding = "UTF-8" as "get less unicodexx errors
fallback")
best wishes,
Harald
--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
no fx, no carrier pigeon
-
LASIK good, steroids bad?
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32