classification
Title: mkdtemp fails on Windows if username has non-ASCII character
Type: behavior Stage: test needed
Components: Library (Lib), Windows Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: loewis Nosy List: BreamoreBoy, georg.brandl, loewis, niemisto, tim.golden
Priority: normal Keywords:

Created on 2007-03-16 10:03 by niemisto, last changed 2010-09-16 22:51 by BreamoreBoy.

Messages (6)
msg31537 - (view) Author: Markus Niemistö (niemisto) Date: 2007-03-16 10:03
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.
msg31538 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-21 11:42
Could you indicate where exactly what error is raised?
msg31539 - (view) Author: Markus Niemistö (niemisto) Date: 2007-04-10 06:48
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)
msg84878 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 19:34
Why are you using a unicode string as your temp directory prefix? Does
it raise something different if you don't?
msg84985 - (view) Author: Markus Niemistö (niemisto) Date: 2009-04-01 06:45
Well, it's not me. As I stated in the problem description, Windows (2000
at least) uses path c:\documents and settings\<user name>\local
settings\temp as default temp dir, where also python tries to make temp
dirs. Now for example if user name is "niemistö", then the temp dir will
be ...\niemistö\local settings\temp, which won't work.

I'll try do test the latest versions of python soon.
msg116632 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-09-16 22:51
I can't reproduce this problem on Windows Vista with any of the current maintainance branches of Python using the interactive prompt from the command line.
History
Date User Action Args
2010-09-16 22:51:43BreamoreBoysetnosy: + BreamoreBoy
messages: + msg116632
2010-08-06 15:11:56tim.goldensetnosy: + tim.golden
2009-04-01 06:45:30niemistosetmessages: + msg84985
2009-03-31 19:34:04georg.brandlsetassignee: loewis

messages: + msg84878
nosy: + loewis
2009-03-30 23:13:56ajaksu2setstage: test needed
type: behavior
components: + Windows
versions: + Python 2.6, - Python 2.5
2007-03-16 10:03:49niemistocreate