import requests https_ip_link = "这里是代理IP的链接" https_ip_list = requests.get(https_ip_link).text.split("\r\n") headers = { "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" } for proxies in https_ip_list: proxies = {"https": 'http://201806091859344402:30494667@{}'.format(proxies)} response = requests.get("https://www.baidu.com/", headers=headers, proxies=proxies, timeout=10) print(response.content.decode())
这是我的爬虫测试代码,在线等,在线等,在线等,希望解决过这个错误或者知道原因的朋友回复我,真心万分感谢。很急切的想知道解决方案。
一直报错如下:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\contrib\pyopenssl.py", line 441, in wrap_socket
cnx.do_handshake()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\OpenSSL\SSL.py", line 1907, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\OpenSSL\SSL.py", line 1632, in _raise_ssl_error
raise SysCallError(-1, "Unexpected EOF")
OpenSSL.SSL.SysCallError: (-1, 'Unexpected EOF')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 595, in urlopen
self._prepare_proxy(conn)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 816, in _prepare_proxy
conn.connect()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connection.py", line 326, in connect
ssl_context=context)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\contrib\pyopenssl.py", line 448, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\adapters.py", line 445, in send
timeout=timeout
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:/project_job/itslaw-spider/trunk/QiChaCha/test/test.py", line 14, in <module>
response = requests.get("https://www.baidu.com/", headers=headers, proxies=proxies, timeout=10)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\adapters.py", line 511, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError:HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')",),))
我已经找了2周这个问题的解决方案,网上都没找到,在解决不了饭碗就没了,急急急急急急求高手解答。万分感谢了
我的版本控制:
ndg-httpsclient 0.5.0
pyasn1 0.4.3
pyOpenSSL 18.0.0
requests 2.19.1
urllib3 1.22
<p>不要沉,顶起来</p>
这份代码爬别的网站正常么?另外有单独研究ssl unexpected eof么?有在stackoverflow上问过了么?
这个代码跑任何https 都这个错,没有去其他地方问
弄一个ssl证书context
<p>我也遇到这个问题了,是不是代理不好呢</p>
<p>楼主解决没,</p>
<p>老哥,我可能也是遇到类似的问题,</p>
requests默认的编码可能与网站的编码不一样
req=requests.get(url=target) #查看request默认的编码,发现与网站response不符,改为网站使用的gbk req.encoding='gbk'
老哥可以试一试
<p>代理ip支不支持https?</p>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。