New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mkdtemp fails on Windows if username has non-ASCII character #44729
Comments
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. |
Could you indicate where exactly what error is raised? |
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) |
Why are you using a unicode string as your temp directory prefix? Does |
Well, it's not me. As I stated in the problem description, Windows (2000 I'll try do test the latest versions of python soon. |
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. |
On Win 7 with a non-ASCII username, this seems to work fine on both 2.7 and 3.3. 2.7 returns str or unicode depending on the type of the "prefix=", whereas 3.3 only accepts str (I think this is expected). I'm going to close this as out of date, feel free to reopen if you can reproduce it on some older but still supported system. |
As detailed in this SO question: http://stackoverflow.com/questions/28101187/deal-with-unicode-usernames-in-python-mkdtemp I still see the issue in 2.7.8. I use a unicode prefix and changing this is not an option (editing legacy code which expects unicode everywhere) Is there some full proof workaround ? Is the one suggested in the OP good enough ? |
The best fix is to use Python 3. In 2015, it's maybe time to use Python 3 which has a very good Unicode support. |
Ubik: this issue is closed, as we believe that it does not exist anymore. If you still think there is a bug surrounding mkdtemp, please make a new full bug report. Structure your report as follows:
Be as precise as possible. For example, reporting the exact user name of the user might be helpful. If you can, debug the problem, e.g. by arranging to display the value of 'path' and 'b' in line 102 of ntpath.py (assuming the error still occurs on the same line as it did for Markus). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: