HTTPS proxy with requests: [Errno 8] _ssl.c: 504: EOF occurred with a protocol violation

I use Requests 1.2.3 on Windows 7 x64 and try to connect to (any) site via HTTPS using an HTTPS proxy, passing the proxies argument to the request.

I do not experience this error when using urllib2 ProxyHandler , so I do not think about it on my proxy side.

 >>> opener = urllib2.build_opener(urllib2.ProxyHandler({'https': 'IP:PORT'})) >>> resp = opener.open('https://www.google.com') >>> resp.url 'https://www.google.co.uk/' >>> resp = requests.get('https://www.google.com', proxies={'https': 'IP:PORT'}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\requests\api.py", line 55, in get return request('get', url, **kwargs) File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request return session.request(method=method, url=url, **kwargs) File "C:\Python27\lib\site-packages\requests\sessions.py", line 335, in request resp = self.send(prep, **send_kwargs) File "C:\Python27\lib\site-packages\requests\sessions.py", line 438, in send r = adapter.send(request, **kwargs) File "C:\Python27\lib\site-packages\requests\adapters.py", line 331, in send raise SSLError(e) requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol 

I should notice that the error repeats if I pass the verify=False request.

Any suggestions? I looked at related questions, but there was nothing that would work for me.

+1
source share
1 answer

I suspect your proxy is an http proxy through which you can use https (the usual case) The problem is that requests use https to communicate with proxies if the request itself is https. Using explicit protocol ( http ) for your proxy server should fix: proxies={'https': 'http://IP:PORT'}

Also see https://github.com/kennethreitz/requests/issues/1182

+3
source

Source: https://habr.com/ru/post/1494006/


All Articles