Message412607
Here's the revised code sample:
import pathlib
import urllib.request
path = "Z:\\test.py"
print(f"Stock open: {pathlib.Path(path).as_uri()}")
with urllib.request.urlopen(pathlib.Path(path).as_uri()) as fp:
data = fp.read()
print(f"Pathlib resolved open: {pathlib.Path(path).resolve().as_uri()}")
with urllib.request.urlopen(pathlib.Path(path).resolve().as_uri()) as fp:
data = fp.read()
and here's the output:
Z:\> python test.py
Stock open: file:///Z:/test.py
Pathlib resolved open: file://host/share/test.py
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\urllib\request.py", line 1505, in open_local_file
stats = os.stat(localfile)
FileNotFoundError: [WinError 2] The system cannot find the file specified: '\\share\\test.py'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Z:\test.py", line 14, in <module>
with urllib.request.urlopen(pathlib.Path(path).resolve().as_uri()) as fp:
File "C:\Program Files\Python310\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\Python310\lib\urllib\request.py", line 519, in open
response = self._open(req, data)
File "C:\Program Files\Python310\lib\urllib\request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Program Files\Python310\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
File "C:\Program Files\Python310\lib\urllib\request.py", line 1483, in file_open
return self.open_local_file(req)
File "C:\Program Files\Python310\lib\urllib\request.py", line 1522, in open_local_file
raise URLError(exp)
urllib.error.URLError: <urlopen error [WinError 2] The system cannot find the file specified: '\\share\\test.py'> |
|
Date |
User |
Action |
Args |
2022-02-05 23:45:49 | ikelos | set | recipients:
+ ikelos, eryksun, barneygale |
2022-02-05 23:45:49 | ikelos | set | messageid: <1644104749.46.0.706902225817.issue46654@roundup.psfhosted.org> |
2022-02-05 23:45:49 | ikelos | link | issue46654 messages |
2022-02-05 23:45:49 | ikelos | create | |
|