因此我一直在使用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天前代码运行良好,我搞混了。
1条答案
按热度按时间2w3kk1z51#
好,我知道了。
pip install --upgrade fake-useragent