You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
open("aux.txt", "w") fails unexpectedly with FileNotFoundError on Windows #81696
I maintain a package which includes a package named "aux.py".
I could not install it on my windows machine via pip and others had the same problem also with windows.
I tracked down the problem to io.open. On my Windows 7 System with Python 3.7.1 from Anaconda, the following statements all result in a FileNotFoundError:
This is a good explanation. Indeed Windows complains if I manually want to create a file "aux.txt" ("This device name is not allowed").
If I want to copy-paste such a file from within a zip-file (Windows Explorer can open zip files) I get an "Unexpected Error".
I think a descriptive error message would be very helpful here. The best mechanism would be if this was generated on system level and then just passed through by io.open to the generated Exception. But just throwing a "FileNotFoundError" without any hint is potentially frustrating.
Suggestion for a better Error message: "Could neither open nor create the desired file. Maybe the filename is not allowed by the underlying os".
DOS device names are reserved in the final component of DOS drive-letter paths. "AUX" (plus an optional colon, spaces, or extension) becomes "\\.\AUX", which is "\??\AUX" in the NT object namespace. By default, "\??\AUX" is a link to "\??\COM1", which, if it exists, is typically a link to "\Device\Serial0". If there's no "COM1", then the kernel returns STATUS_OBJECT_NAME_NOT_FOUND, which the Windows API translates to ERROR_FILE_NOT_FOUND, which the C runtime translates to ENOENT, and finally Python raises FileNotFoundError.
Accessing a DOS device name requires using a device path (prefixed by "\\.\" or "\\?\", and forward slash is okay, e.g. "//./C:/Temp/aux.py") or a UNC path (e.g. "//localhost/C$/Temp/aux.py"). That said, if we create a file like this, programs that use regular drive-letter paths won't be able to access it. It's better to sanitize reserved DOS device names. This includes "CONIN$" and "CONOUT$", even though Microsoft's documentation overlooks these two.
For future reference, please don't post screen shots of plain text, as they make it unnecessarily difficult for blind or visually impaired developers to contribute (and yes, they do exist, I've worked with some, and at least one core developer). Copy the relevant text (including the exception traceback) and paste them into the bug report.
Activity
httpsgithubcomcknoll commentedon Jul 6, 2019
I maintain a package which includes a package named "aux.py".
I could not install it on my windows machine via pip and others had the same problem also with windows.
I tracked down the problem to
io.open. On my Windows 7 System with Python 3.7.1 from Anaconda, the following statements all result in a FileNotFoundError:On the other hand the following commands work as expected:
etc.
Can anybody confirm this?
On Linux (I could not reproduce the problem.)
SilentGhost commentedon Jul 6, 2019
aux is one of the reserved filenames on windows: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
I don't think Python can do anything about that.
httpsgithubcomcknoll commentedon Jul 6, 2019
This is a good explanation. Indeed Windows complains if I manually want to create a file "aux.txt" ("This device name is not allowed").
If I want to copy-paste such a file from within a zip-file (Windows Explorer can open zip files) I get an "Unexpected Error".
I think a descriptive error message would be very helpful here. The best mechanism would be if this was generated on system level and then just passed through by io.open to the generated Exception. But just throwing a "FileNotFoundError" without any hint is potentially frustrating.
Suggestion for a better Error message: "Could neither open nor create the desired file. Maybe the filename is not allowed by the underlying os".
eryksun commentedon Jul 6, 2019
DOS device names are reserved in the final component of DOS drive-letter paths. "AUX" (plus an optional colon, spaces, or extension) becomes "\\.\AUX", which is "\??\AUX" in the NT object namespace. By default, "\??\AUX" is a link to "\??\COM1", which, if it exists, is typically a link to "\Device\Serial0". If there's no "COM1", then the kernel returns STATUS_OBJECT_NAME_NOT_FOUND, which the Windows API translates to ERROR_FILE_NOT_FOUND, which the C runtime translates to ENOENT, and finally Python raises FileNotFoundError.
Accessing a DOS device name requires using a device path (prefixed by "\\.\" or "\\?\", and forward slash is okay, e.g. "//./C:/Temp/aux.py") or a UNC path (e.g. "//localhost/C$/Temp/aux.py"). That said, if we create a file like this, programs that use regular drive-letter paths won't be able to access it. It's better to sanitize reserved DOS device names. This includes "CONIN$" and "CONOUT$", even though Microsoft's documentation overlooks these two.
stevendaprano commentedon Jul 6, 2019
For future reference, please don't post screen shots of plain text, as they make it unnecessarily difficult for blind or visually impaired developers to contribute (and yes, they do exist, I've worked with some, and at least one core developer). Copy the relevant text (including the exception traceback) and paste them into the bug report.
Thank you.