在使用之前的代码时,报错:
Traceback (most recent call last):
File “xxx”, line xx, in
req = requests.get(url, headers=headers, proxies=proxies, timeout=(3,7))
ValueError: Timeout value connect was Timeout(connect=2.0, read=2.0, total=None), but it must be an int or float.
Traceback (most recent call last):
File "xxx", line xx, in <module>
req = requests.get(url, headers=headers, proxies=proxies, timeout=(3,7))
ValueError: Timeout value connect was Timeout(connect=2.0, read=2.0, total=None), but it must be an int or float.
主要报错信息内容翻译如下所示:
Traceback (most recent call last):
File "xxx", line xx, in <module>
req = requests.get(url, headers=headers, proxies=proxies, timeout=(3,7))
ValueError: Timeout value connect was Timeout(connect=2.0, read=2.0, total=None), but it must be an int or float.
翻译:
追溯(最近一次通话):
文件“xxx”,第xx行,在中
req=requests.get(url,headers=headers,proxys=proxys,timeout=(3,7))
ValueError:超时值connect为Timeout(connect=2.0,read=2.0,total=None),但它必须是int或float。
req = requests.get(url, headers=headers, proxies=proxies, timeout=(3,7))
经过查阅资料,发现这个请求超时的原因可能是由于python-requests version 2.4.3-4版本的bug导致的,也可能是Selenium版本与urllib版本冲突导致的,需要根据情况进一步采取相应的处理措施。
小伙伴们按下面的解决方法即可解决!!!
要解决这个错误,需要这里总结了以下几个解决办法。
正确的命令是:
pip install -U requests
更换urllib3 2.0.7版本到1.26的命令是:
pip uninstall urllib3
pip install urllib3 == 1.26.2
或更换Selenium降级版本的命令是:
pip install --force-reinstall -v "selenium==2.53.0"