编写爬虫时使用代理出现 ConnectionResetError: [Errno 54]错误怎么解决?

0

import requests headers = { 'Accept':'application/json, text/plain, */*', 'Accept-Language':'zh-CN,zh;q=0.8', 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' } proxies = {'http': 'http://117.63.8.194:9287', 'https': 'http://117.63.8.194:9287'} url = 'https://www.zhihu.com/' html = requests.get(url, headers=headers,proxies=proxies) print(html)代理可以用的,不用代理就没事,用代理访问其他网站一样报这个错误

ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='http://www.zhihu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(54, 'Connection reset by peer')))




During handling of the above exception, another exception occurred:

requests.exceptions.ProxyError: HTTPSConnectionPool(host='http://www.zhihu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(54, 'Connection reset by peer')))
已邀请:
0

一只写程序的猿 - 一个圣骑士成熟的标志是不再向盲人解释阳光。公众号:Python攻城狮 2017-10-26 回答

可以在抛出异常,使用别的代理或者代理池
0

ID王大伟 - 人生苦短,我选Python。 2017-09-26 回答

换个代理试试

要回复问题请先登录注册