我想使用以下代码用urllib.request.urlopen
打开本地文件:
urllib.request.urlopen('file:///home/parham/.bashrc')
但是它会产生以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, 'default',
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 806, in <lambda>
meth(r, proxy, type))
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 834, in proxy_open
return self.parent.open(req, timeout=req.timeout)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
我做对了吗?还是与urllib
有关?
答案 0 :(得分:0)
此问题与shell-proxy
的{{1}}插件有关。禁用它之后,一切都会像以前一样工作。