urllib.error.HTTPError:HTTP错误403:python中禁止

时间:2020-04-23 11:41:15

标签: python web-scraping

import urllib.request  # the lib that handles the url stuff

for line in urllib.request.urlopen('https://www.py4e.com/code3/mbox.txt'):
    print(line.decode('utf-8'))

我正在跟随错误

Traceback (most recent call last):
  File "C:/Users/JeevanKumar/Documents/Python Programs/ReadData.py", line 3, in <module>
    for line in urllib.request.urlopen('https://www.py4e.com/code3/mbox.txt'):
  File "C:\Users\JeevanKumar\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\JeevanKumar\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\JeevanKumar\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 640, in http_response
    response = self.parent.error(
  File "C:\Users\JeevanKumar\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Users\JeevanKumar\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Users\JeevanKumar\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

0 个答案:

没有答案