Request.exceptions.SSLError: [Errno 8] _ssl.c: 504: EOF occurred with protocol violation

I tried everything on this q & a to solve this problem, but I still get this error.

My last attempt is based on Lukasa's comment , and my code is as follows:

import requests from requests.adapters import HTTPAdapter from requests.packages.urllib3.poolmanager import PoolManager import ssl class MyAdapter(HTTPAdapter): def init_poolmanager(self, connections, maxsize, block=False): self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block, ssl_version=ssl.PROTOCOL_TLSv1) proxy = 'https://78.130.136.2:8080' g = 'https://www.google.com/' s = requests.Session() s.mount('https://', MyAdapter()) r = s.get(g, proxies={'https': proxy} ) print r.text.encode('utf-8') 

I get the full error:

 Traceback (most recent call last): File "/Users/Dionysis_Lorentzos/Projects/getter/proxy.py", line 30, in <module> r = s.get(g, proxies={'https': proxy}, verify=True ) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 347, in get return self.request('GET', url, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 335, in request resp = self.send(prep, **send_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 438, in send r = adapter.send(request, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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 

So, how can I get site data with a proxy server through https ? (proxy works fine in my Firefox)

+1
source share
2 answers

In all versions of PyPI requests, there is no support for requesting HTTPS sites over a proxy server, because CONNECT verb support is not supported. Our preview version for version 2.0 supports this support, and it works on every proxy server I tried. If you want to check this out and try it out, you also won't need a custom adapter.

Otherwise, you have to wait until we release 2.0

+1
source

You should use http as the protocol for your proxy (although you use https over it)

 proxy = 'http://78.130.136.2:8080' 

But, like @ sigmavirus24, there are some problems with the http proxy in the current version of the requests. With this parameter you can use proxies (not all proxies, but this proxy, in particular, works).

Be careful: In the current version, data is NOT encrypted between you and your proxy.

Repeat: proxy and everything in between and you can read the data!

0
source

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


All Articles