彻底解决 fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

话说这个  fake_useragent 是实在烦人, 每隔一段时间执行脚本都是这个东西报错, 

来, 给大家康康今天又作了什么妖,报了什么错

Connected to pydev debugger (build 181.5087.20)
Traceback (most recent call last):
  File "D:\py\lib\urllib\request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "D:\py\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "D:\py\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "D:\py\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "D:\py\lib\http\client.py", line 1016, in _send_output
    self.send(msg)
  File "D:\py\lib\http\client.py", line 956, in send
    self.connect()
  File "D:\py\lib\http\client.py", line 1384, in connect
    super().connect()
  File "D:\py\lib\http\client.py", line 928, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "D:\py\lib\socket.py", line 727, in create_connection
    raise err
  File "D:\py\lib\socket.py", line 716, in create_connection
    sock.connect(sa)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 67, in get
    context=context,
  File "D:\py\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "D:\py\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "D:\py\lib\urllib\request.py", line 543, in _open
    '_open', req)
  File "D:\py\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "D:\py\lib\urllib\request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "D:\py\lib\urllib\request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error timed out>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\DELL\.IntelliJIdea2018.1\config\plugins\python\helpers\pydev\pydevd.py", line 1664, in <module>
    main()
  File "C:\Users\DELL\.IntelliJIdea2018.1\config\plugins\python\helpers\pydev\pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Users\DELL\.IntelliJIdea2018.1\config\plugins\python\helpers\pydev\pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Users\DELL\.IntelliJIdea2018.1\config\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "F:/workSpace/agent_idea/client/src/main/py/TaxRateSpider.py", line 12, in <module>
    ua = UserAgent(use_cache_server=False)
  File "D:\py\lib\site-packages\fake_useragent\fake.py", line 69, in __init__
    self.load()
  File "D:\py\lib\site-packages\fake_useragent\fake.py", line 78, in load
    verify_ssl=self.verify_ssl,
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 250, in load_cached
    update(path, use_cache_server=use_cache_server, verify_ssl=verify_ssl)
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 245, in update
    write(path, load(use_cache_server=use_cache_server, verify_ssl=verify_ssl))
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 178, in load
    raise exc
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 154, in load
    for item in get_browsers(verify_ssl=verify_ssl):
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 97, in get_browsers
    html = get(settings.BROWSERS_STATS_PAGE, verify_ssl=verify_ssl)
  File "D:\py\lib\site-packages\fake_useragent\utils.py", line 84, in get
    raise FakeUserAgentError('Maximum amount of retries reached')
fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

Process finished with exit code 1

 

这是我脚本使用 fake_useragent 姿势

 

 

解决方法:

1: 下载 fake_useragent.json

链接:https://pan.baidu.com/s/1hVKe476erO9V6_2KAlA8lg 
提取码:b4m4 

 

2: 将json文件放到目录下 (这里我放的位置是跟我这个脚本同级目录, 你们也可以看这来, 只要确保下面的代码可以获取到这个json文件即可)

 

3:修改代码

 

location = os.getcwd() + '/fake_useragent_0.1.11.json'
ua = UserAgent(path=location)


4: 点赞,评论,收藏  一键三连

 

 

 

 

 

 

 

 

  • 7
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值