[New-bugs-announce] [issue35306] OSError [WinError 123] when testing if pathlib.Path('*') (asterisks) exists
jimbo1qaz_ via Gmail
report at bugs.python.org
Sat Nov 24 00:55:59 EST 2018
New submission from jimbo1qaz_ via Gmail <jimbo1qaz at gmail.com>:
I'm writing a program taking paths from user input through CLI.
`path` is a pathlib.Path().
Since Windows doesn't expand asterisks, I check if the path doesn't exist. If so I expand using Path().glob(path).
Unfortunately on Windows, if `path` (type: Path) contains asterisks, checking `path.exists()` or `path.is_dir()` raises WinError 123.
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('*').exists()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1318, in exists
self.stat()
File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1140, in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '*'
>>> Path('*').is_dir()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1330, in is_dir
return S_ISDIR(self.stat().st_mode)
File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1140, in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '*'
I also reproduced on Miniconda 3.6.6, 3.7.0, and official Python 3.7.1.
According to https://bugs.python.org/issue29827 , os.path.exists() (not Path.exists() ) returns False on any OSError.
-----------------
On Linux, checking paths with null bytes (a less common occurrence) raises a different error:
>>> import pathlib
>>> pathlib.Path("\x00").exists()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/pathlib.py", line 1336, in exists
self.stat()
File "/usr/lib/python3.6/pathlib.py", line 1158, in stat
return self._accessor.stat(self)
File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped
return strfunc(str(pathobj), *args)
ValueError: embedded null byte
----------
components: Library (Lib)
messages: 330371
nosy: jimbo1qaz_
priority: normal
severity: normal
status: open
title: OSError [WinError 123] when testing if pathlib.Path('*') (asterisks) exists
versions: Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35306>
_______________________________________
More information about the New-bugs-announce
mailing list