[ python-Bugs-1681974 ] mkdtemp fails on Windows if username has non-ASCII character

SourceForge.net noreply at sourceforge.net
Tue Apr 10 08:48:34 CEST 2007


Bugs item #1681974, was opened at 2007-03-16 12:03
Message generated for change (Comment added) made by niemisto
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1681974&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Markus Niemistö (niemisto)
Assigned to: Nobody/Anonymous (nobody)
Summary: mkdtemp fails on Windows if username has non-ASCII character

Initial Comment:
mkdtemp fails miserably on Windows if Windows user name has any non-ASCII characters, like ä or ö, in it. mkdtemp throws an encoding error.

This seems to be because the default temp dir in Windows is "c:\documents and settings\<user name>\local settings\temp". Now if the user name has non-ASCII characters ASCII decoder cannot handle it and creating temp directories won't work.

As a work around I have used the following code:

tempdir = unicode(tempfile.gettempdir(), 'mbcs')
mkdtemp(suffix='foo', dir=tempdir)

This applies for both Python 2.4 and Python 2.5.

----------------------------------------------------------------------

>Comment By: Markus Niemistö (niemisto)
Date: 2007-04-10 09:48

Message:
Logged In: YES 
user_id=459586
Originator: YES

Here is traceback. Sorry it took so long.

Traceback (most recent call last):
  File "c:\util\home\xxx\xxx.py", line 350, in OnOpen
    dir = tempfile.mkdtemp(prefix=u'test')
  File "C:\python24\lib\tempfile.py", line 326, in mkdtemp
    file = _os.path.join(dir, prefix + name + suffix)
  File "c:\python24\lib\ntpath.py", line 102, in join
    path += "\\" + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 12:
ordinal not in range(128)


----------------------------------------------------------------------

Comment By: Georg Brandl (gbrandl)
Date: 2007-03-21 13:42

Message:
Logged In: YES 
user_id=849994
Originator: NO

Could you indicate where exactly what error is raised?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1681974&group_id=5470


More information about the Python-bugs-list mailing list