request报错requests.exceptions.ConnectionError以及requests.exceptions.ConnectTimeout

标签:
python爬虫requests |
分类: Python |
使用request库爬虫tensorflow的API的时候报错,信息如下:
requests.exceptions.ConnectionError:
HTTPSConnectionPool(host='www.tensorflow.or
g', port=443): Max retries exceeded with url:
/api_docs/python/ (Caused by NewCo
nnectionError('
ect at 0x01C3DA10>: Failed to establish a new connection:
[Errno 10060] ',))
requests.exceptions.ConnectTimeout:
HTTPSConnectionPool(host='www.tensorflow.org
', port=443): Max retries exceeded with url: /api_docs/python/
(Caused by Connec
tTimeoutError(
ct at 0x01CA4A10>, 'Connection to www.tensorflow.org timed
out. (connect timeout
=10)'))
很显然是连接不上,需要dai[fenge]li才能连接上
在request中设置代理,不过需要注意的是,这里访问网站的方式是https不是http,所以代理设置如下:
proxy = {"https":"dai[]li_IP"}
然后在requests的get方法中指定如下:
requests.get(url, proxies=proxy)
即可解决问题