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
WindowsError messages are not properly encoded #46094
Comments
The message for WindowsError is taken from the Windows API's >>> import os
>>> os.rmdir('E:\\temp')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
WindowsError: [Error 41] A pasta nÒo estß vazia: 'E:\\temp' Should be: "A pasta não está vazia" [Folder is not empty]. Python could check what is the code page of the current output interface |
Crys, can you confirm this? It would seem we'll need to fix this twice -- once for 2.x, once for 3.0. |
Oh nice ... Amaury knows probably more about the wide char Windows API than me. The |
I confirm the problem (with French accents) on python 2.5. We could do the same for python 2.5, but the error message must be |
"... but the error message must be converted to str early (i.e when Wouldn't that create more problems? What if somebody wants to intercept |
I think this is not possible if we want to preserve compatibility; at I can see different solutions:
My preferred being 1): python2.5 is mostly encoding-naive, python3 is |
3.0 will be a long way away for many users. Perhaps forcing English |
I would claim that this is not a bug. Sure, the message doesn't come out IIUC, the problem is that Python computes the message in CP_ACP (i.e. If we declare that all strings are considered as CP_ACP in the Forcing English messages would certainly reduce the problems, but it |
If this is chosen, I propose to use CharToOem as the "unfailing" |
Sounds fine to me. |
Here is a patch. Now I feel it is a hack, but it is the only place I |
I think WindowsError's message should be English like other errors. |
On a non-english system FormatMessageW fails with ERROR_RESOURCE_LANG_NOT_FOUND (The specified resource language ID cannot be found in the image file) when called with that parameter. |
Should we close this? There was some opinion that this is not a bug. The argument for not closing this before "3.0 will be a long way away for many users." is obsolete as 3.1.2 is here and 3.2 will be in less than 6 months. Or, Amaury, do you have any serious prospect of applying the patch to 2.7? |
Somebody should investigate the status of this on 3.x. If the message comes out as a nice Unicode string, I'd close it as fixed. If the message comes out as a byte string, it definitely needs fixing. For 2.x, the issue is out of date. |
The message is definitely an str (unicode) string. WinXP,3.1.2, import os
try: os.rmdir('nonexist')
except Exception as e:
print(repr(e.args[1]), '\n', repr(e.strerror), '\n', e.filename)
os.rmdir('nonexist') # prints |
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: