встретился с похожей проблемой.
При использовании urllib.request.urlopen(url)
выдает ошибки:
Traceback (most recent call last):
File “<pyshell#2>”, line 1, in <module>
f = urllib.request.urlopen(url)
File “E:\pithon\lib\urllib\request.py”, line 191, in urlopen
return opener.open(url, data, timeout)
File “E:\pithon\lib\urllib\request.py”, line 495, in open
response = meth(req, response)
File “E:\pithon\lib\urllib\request.py”, line 603, in http_response
‘http’, request, response, code, msg, hdrs)
File “E:\pithon\lib\urllib\request.py”, line 533, in error
return self._call_chain(*args)
File “E:\pithon\lib\urllib\request.py”, line 467, in _call_chain
result = func(*args)
File “E:\pithon\lib\urllib\request.py”, line 611, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
вот код:
import urllib.request, urllib.parse, urllib.error
url = '
http://www.py4e.com/code3/mbox.txt'
f = urllib.request.urlopen(url).read()
print(f)