使用包fake_useragent Python 3时“达到最大重试次数”

py49o6xq  于 2022-12-20  发布在  Python
关注(0)|答案(1)|浏览(261)

因此我一直在使用fake_useragent进行一个Web抓取项目:

from fake_useragent import UserAgent
ua = UserAgent()
headers = {
    "User-Agent":ua.random
}

但是我最近在Python 3中收到了这个错误:

Error occurred during loading data. Trying to use cache server file https://useragent.melroy.org/cache.json
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/fake_useragent/utils.py", line 64, in get
    urlopen(
  File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
....skip...

fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

2天前代码运行良好,我搞混了。

2w3kk1z5

2w3kk1z51#

好,我知道了。pip install --upgrade fake-useragent

相关问题