Got ssl.SSLEOFError when working behind a vpn - python

I m working behind a vpn and trying to use python requests, but I keep getting ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1123). Once I turned down the vpn it worked as excepted. Is there any way to work around this issue?
Also one thing worth noting is that I tried to use postman while the vpn was on, and it worked fine.
Example
import requests
requests.get('https://www.google.com')
Traceback (most recent call last):
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\connectionpool.py", line 700, in urlopen
self._prepare_proxy(conn)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\connectionpool.py", line 994, in _prepare_proxy
conn.connect()
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\connection.py", line 364, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\connection.py", line 501, in _connect_tls_proxy
socket = ssl_wrap_socket(
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "D:\Programming\Python\Python39\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "D:\Programming\Python\Python39\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "D:\Programming\Python\Python39\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Programming\Projects\Python\Scripts\crawling\util.py", line 197, in <module>
main()
File "D:\Programming\Projects\Python\Scripts\crawling\util.py", line 189, in main
requests.get('https://www.google.com')
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "D:\Programming\Projects\Python\Scripts\venv\lib\site-packages\requests\adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)')))
Thanks in advance.

Related

How can you disable SSL verification in urlib3?

I am getting this error:
Traceback (most recent call last):
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/connection.py", line 416, in connect
self.sock = ssl_wrap_socket(
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.example.com', port=8080): Max retries exceeded with url: /geoserver/ows?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=qazqoinau_test%3A%D0%93%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0%20%D0%A0%D0%B5%D1%81%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D0%BA%D0%B8%20%D0%9A%D0%B0%D0%B7%D0%B0%D1%85%D1%81%D1%82%D0%B0%D0%BD&STYLES=qazqoinau_test%3Alayers_border_RK&SRS=EPSG%3A3857&CRS=EPSG%3A3857&TILED=true&access_token=JNkYj4bIfuWQbQu06AAF2MUxc9banx&WIDTH=512&HEIGHT=512&BBOX=2504688.542848654%2C2504688.542848654%2C5009377.08569731%2C5009377.08569731 (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url,verify=False,**kwargs)
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/home/adminko/.geonodevirtaulenvs/geonode/lib/python3.8/site-packages/requests/adapters.py", line 563, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.example.com', port=8080): Max retries exceeded with url: /geoserver/ows?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=qazqoinau_test%3A%D0%93%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0%20%D0%A0%D0%B5%D1%81%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D0%BA%D0%B8%20%D0%9A%D0%B0%D0%B7%D0%B0%D1%85%D1%81%D1%82%D0%B0%D0%BD&STYLES=qazqoinau_test%3Alayers_border_RK&SRS=EPSG%3A3857&CRS=EPSG%3A3857&TILED=true&access_token=JNkYj4bIfuWQbQu06AAF2MUxc9banx&WIDTH=512&HEIGHT=512&BBOX=2504688.542848654%2C2504688.542848654%2C5009377.08569731%2C5009377.08569731 (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))
How can I disable checking this SSL verification or how can I handle this error (consequences after changing )? I am ready to change package code to handle this error. Everything was working when I was using HTTP connection.
I have already changed request.get(verify = False)
my code
import requests
requests.get('https://www.example.com:8080/geoserver/ows?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=qazqoinau_test%3A%D0%93%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0%20%D0%A0%D0%B5%D1%81%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D0%BA%D0%B8%20%D0%9A%D0%B0%D0%B7%D0%B0%D1%85%D1%81%D1%82%D0%B0%D0%BD&STYLES=qazqoinau_test%3Alayers_border_RK&SRS=EPSG%3A3857&CRS=EPSG%3A3857&TILED=true&access_token=JNkYj4bIfuWQbQu06AAF2MUxc9banx&WIDTH=512&HEIGHT=512&BBOX=2504688.542848654%2C2504688.542848654%2C5009377.08569731%2C5009377.08569731')

pyTelegramBotAPI connection problem or what?

this is my code:
import telebot
bot = telebot.TeleBot(Token)
#bot.message_handler(commands=["greet"])
def greeting(message):
bot.reply_to(message, "Hi")
bot.polling()
and this is the error I receive:
Traceback (most recent call last):
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 496, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\ssl_.py", line 432, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\ssl_.py", line 474, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1494641875:AAEPX72rP7YFT0ZZzASh0cn9rAw6l8PUMk0/getUpdates?offset=1&timeout=20 (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:/Programming/Python/Training/TelegramBot02/main.py", line 13, in <module>
bot.polling()
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 455, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 513, in __threaded_polling
raise e
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 478, in __threaded_polling
polling_thread.raise_exceptions()
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 88, in raise_exceptions
raise self.exception_info
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 295, in __retrieve_updates
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout, long_polling_timeout = long_polling_timeout)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 265, in get_updates
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates, long_polling_timeout)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 248, in get_updates
return _make_request(token, method_url, params=payload)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 107, in _make_request
result = _get_req_session().request(
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1494641875:AAEPX72rP7YFT0ZZzASh0cn9rAw6l8PUMk0/getUpdates?offset=1&timeout=20 (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
Connection is OK. Token is OK. It works manually when I browse https://api.telegram.org/botToken/getme and it works fine.
Other site for example google.com are OK too and works fine.
I would be glad to know what is the problem.
Actually because error I receive is too much a lot, stackoverflow does not allow me to post the question and wants me to add some more details, so I wrote this paragraph which is not related to the question and is just some words.
Do you have connected your telegram with a proxy? I can't solve your problem but you can follow this post: Problem connecting telegram bot through Python

Installing a Python Library on Windows 10; with proxy set on [duplicate]

When sending a request with authentication, I get a requests.exceptions.SSLError error which you can See below.
proxies = { 'https' : "http://user:pass#ip:port/" }
url = "https://httpbin.org/ip"
numberResponse = requests.get(url,proxies=proxies).text
print(numberResponse)
The requests.exceptions.SSLError
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 496, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 428, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 472, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1125)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/K_Yuk/OneDrive/Desktop/Gmail generator/test.py", line 15, in <module>
numberResponse = requests.get(url,proxies=proxies).text
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)')))
So then I tired verify=False as one of the requests.get() parameters but then get a requests.exceptions.ProxyError error which you can see below :
proxies = { 'https' : "http://user:pass#10.10.1.10:3128/"}
url = "https://httpbin.org/ip"
numberResponse = requests.get(url,proxies=proxies,verify=False).text
print(numberResponse)
The requests.exceptions.ProxyError
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 496, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 428, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 472, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/K_Yuk/OneDrive/Desktop/Gmail generator/test.py", line 15, in <module>
numberResponse = requests.get(url,proxies=proxies,verify=False).text
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory')))
I tired to look every for the answer but nothing seems to work. I can't send a request with a proxy with
authentication. Any ideas?
The problem is very likely not the authentication. Unfortunately, you don't provide details of the proxy configuration and the URL you use for the proxy. The only thing you provide is:
proxies = { 'https' : eampleIpWithAuth }
Based on the reference to _connect_tls_proxy in the stacktrace the eampleIpWithAuth is very likely something like https://..., i.e. you try to access the proxy itself over HTTPS. Note that accessing a proxy over HTTPS is different from using a HTTP proxy for HTTPS. When accessing a HTTPS URL over a HTTPS proxy one essentially does double encryption to the proxy:
client --- [HTTPS wrapped inside HTTPS] --- proxy --- [HTTPS] --- server
Whereas with a HTTPS URL over a "normal" HTTP proxy there is only single encryption, i.e. it looks (simplified) like this:
client --- [HTTPS wrapped inside HTTP] --- proxy --- [HTTPS] --- server
Very likely the proxy you want to use is a plain HTTP proxy, and not a HTTPS proxy. This is actually the most common case.
The error happens since the proxy is not able to speak TLS but gets accessed by TLS. The fix is to use http://proxy and not https://proxy as the proxy address. Note that the latter worked in older versions of Python since proxy over HTTPS was not supported and a value of https:// for the protocol was treated the same as http://.
I had a similar problem with my script in python 3.9 version.
When I try to get some data from web server, I had exception like Your:
urllib3.exceptions.MaxRetryError
Simple add this line to configure Your requests
import requests
import urllib3
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL:#SECLEVEL=1'
I hope, this help You to solve Your issue

How to get around python requests SSL and proxy error?

When sending a request with authentication, I get a requests.exceptions.SSLError error which you can See below.
proxies = { 'https' : "http://user:pass#ip:port/" }
url = "https://httpbin.org/ip"
numberResponse = requests.get(url,proxies=proxies).text
print(numberResponse)
The requests.exceptions.SSLError
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 496, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 428, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 472, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1125)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/K_Yuk/OneDrive/Desktop/Gmail generator/test.py", line 15, in <module>
numberResponse = requests.get(url,proxies=proxies).text
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)')))
So then I tired verify=False as one of the requests.get() parameters but then get a requests.exceptions.ProxyError error which you can see below :
proxies = { 'https' : "http://user:pass#10.10.1.10:3128/"}
url = "https://httpbin.org/ip"
numberResponse = requests.get(url,proxies=proxies,verify=False).text
print(numberResponse)
The requests.exceptions.ProxyError
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 496, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 428, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 472, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/K_Yuk/OneDrive/Desktop/Gmail generator/test.py", line 15, in <module>
numberResponse = requests.get(url,proxies=proxies,verify=False).text
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory')))
I tired to look every for the answer but nothing seems to work. I can't send a request with a proxy with
authentication. Any ideas?
The problem is very likely not the authentication. Unfortunately, you don't provide details of the proxy configuration and the URL you use for the proxy. The only thing you provide is:
proxies = { 'https' : eampleIpWithAuth }
Based on the reference to _connect_tls_proxy in the stacktrace the eampleIpWithAuth is very likely something like https://..., i.e. you try to access the proxy itself over HTTPS. Note that accessing a proxy over HTTPS is different from using a HTTP proxy for HTTPS. When accessing a HTTPS URL over a HTTPS proxy one essentially does double encryption to the proxy:
client --- [HTTPS wrapped inside HTTPS] --- proxy --- [HTTPS] --- server
Whereas with a HTTPS URL over a "normal" HTTP proxy there is only single encryption, i.e. it looks (simplified) like this:
client --- [HTTPS wrapped inside HTTP] --- proxy --- [HTTPS] --- server
Very likely the proxy you want to use is a plain HTTP proxy, and not a HTTPS proxy. This is actually the most common case.
The error happens since the proxy is not able to speak TLS but gets accessed by TLS. The fix is to use http://proxy and not https://proxy as the proxy address. Note that the latter worked in older versions of Python since proxy over HTTPS was not supported and a value of https:// for the protocol was treated the same as http://.
I had a similar problem with my script in python 3.9 version.
When I try to get some data from web server, I had exception like Your:
urllib3.exceptions.MaxRetryError
Simple add this line to configure Your requests
import requests
import urllib3
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL:#SECLEVEL=1'
I hope, this help You to solve Your issue

python proxy request can't fetch data from www.google.com

I use Shadowsocks to get out from the Chinese GFW. It works fine when I use chrome to browse www.google.com.
Recently I am learning something about python crawlers, and I want to fetch data from www.google.com by using request.
I learned that I have to set proxy to get out from the GFW, and the code is like
import socket
import socks
import requests
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
socket.socket = socks.socksocket
print(requests.get('http://ifconfig.me/ip').text)
and then I get the address of my Shadowsocks server
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/lsongseven/PycharmProjects/wordcloud/cl.py
52.73.41.9
and here is my Shadowsocks configuration
enter image description here
However, when I use this script to fetch data from google, it doesn't work anymore
import socket
import socks
import requests
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
socket.socket = socks.socksocket
print(requests.get('https://www.google.com/').text)
Here is the error message:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/lsongseven/PycharmProjects/wordcloud/cl.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connection.py", line 326, in connect
ssl_context=context)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 376, in wrap_socket
_context=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 747, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:646)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:646)'),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/lsongseven/PycharmProjects/wordcloud/cl.py", line 7, in <module>
print(requests.get('https://www.google.com/').text)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:646)'),))
So the problem is that Shadowsocks works fine but the python script cannot work, does anyone have some suggestions?
"SSLEOFError" Seems like OpenSSL cause this prolbem.
You may try to upgrade your OpenSSL viesion,or reinstall OpenSSl.

Categories