Python proxy ssl error

On Windows you can only set a "host:port" http proxy as system proxy. PS > Get-ItemProperty -Path 'HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet Settings' | findstr ...

On Windows you can only set a «host:port» http proxy as system proxy.

PS > Get-ItemProperty -Path 'HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet Settings' | findstr ProxyServer
ProxyServer              : 127.0.0.1:7890

But in Python, it assumes that this proxy supports both http and https on the same port:

>>> import urllib
>>> urllib.request.getproxies()
{'http': 'http://127.0.0.1:7890', 'https': 'https://127.0.0.1:7890', 'ftp': 'ftp://127.0.0.1:7890'}

Which will try to handshake httpps on http port.

Expected Result

On Python 3.8.x:

> .python38.exe
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib, requests
>>> urllib.request.getproxies()
{'http': 'http://127.0.0.1:7890', 'https': 'https://127.0.0.1:7890', 'ftp': 'ftp://127.0.0.1:7890'}
>>> requests.get("http://www.google.com")
<Response [200]>
>>> requests.get("https://www.google.com")
<Response [200]>

Actual Result

> python3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib, requests
>>> urllib.request.getproxies()
{'http': 'http://127.0.0.1:7890', 'https': 'https://127.0.0.1:7890', 'ftp': 'ftp://127.0.0.1:7890'}
>>> requests.get("http://www.google.com")
<Response [200]>
>>> requests.get("https://www.google.com")
Traceback (most recent call last):
  File "C:Python39libsite-packagesurllib3connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "C:Python39libsite-packagesurllib3connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:Python39libsite-packagesurllib3connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "C:Python39libsite-packagesurllib3connection.py", line 496, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "C:Python39libsite-packagesurllib3utilssl_.py", line 432, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "C:Python39libsite-packagesurllib3utilssl_.py", line 474, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "C:Python39libssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:Python39libssl.py", line 1040, in _create
    self.do_handshake()
  File "C:Python39libssl.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 "C:Python39libsite-packagesrequestsadapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:Python39libsite-packagesurllib3connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:Python39libsite-packagesurllib3utilretry.py", line 573, 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 "<stdin>", line 1, in <module>
  File "C:Python39libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:Python39libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:Python39libsite-packagesrequestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:Python39libsite-packagesrequestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:Python39libsite-packagesrequestsadapters.py", line 514, 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)')))

Reproduction Steps

Set a http Windows system proxy then execute:

import requests
requests.get("https://www.google.com")

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.1"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "1010107f"
  },
  "urllib3": {
    "version": "1.26.2"
  },
  "using_pyopenssl": false
}

SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates. We will cover how to fix this issue in 4 ways in this article.

Why certificate_verify_failed  happen?

The SSL connection will be established based on the following process.   We will get errors if any of these steps does not go well.

For this error certificate_verify_failed, it usually happens during step 2 and step 3.

  • The client sends a request to the server for a secure session. The server responds by sending its X.509 digital certificate to the client.
  • The client receives the server’s X.509 digital certificate.
  • The client authenticates the server, using a list of known certificate authorities.
  • The client generates a random symmetric key and encrypts it using server’s public key.
  • The client and server now both know the symmetric key and can use the SSL encryption process to encrypt and decrypt the information contained in the client request and the server response.

When the client receives the server’s certificate, it begins chaining that certificate back to its root. It will begin by following the chain to the intermediate that has been installed, from there it continues tracing backwards until it arrives at a trusted root certificate.

If the certificate is valid and can be chained back to a trusted root, it will be trusted. If it can’t be chained back to a trusted root, the browser will issue a warning about the certificate.

Related: Check SSL Certificate Chain with OpenSSL Examples

Error info about certificate_verify_failed

We will see the following error.

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

What is SSL certificate

Server certificates are the most popular type of X.509 certificate. SSL/TLS certificates are issued to hostnames (machine names like ‘ABC-SERVER-02’ or domain names like google.com).

A server certificate is a file installed on a website’s origin server. It’s simply a data file containing the public key and the identity of the website owner, along with other information. Without a server certificate, a website’s traffic can’t be encrypted with TLS.

Technically, any website owner can create their own server certificate, and such certificates are called self-signed certificates. However, browsers do not consider self-signed certificates to be as trustworthy as SSL certificates issued by a certificate authority.

Related: 2 Ways to Create self signed certificate with Openssl Command

How to fix certificate_verify_failed?

If you receive the “certificate_verify_failed” error when trying to connect to a website, it means that the certificate on the website is not trusted. There are a few different ways to fix this error.

We will skip the SSL certificate check in the first three solutions.  For the fourth solution, we are going to install the latest CA certificate from certifi.

Create unverified context in SSL

import ssl
context = ssl._create_unverified_context()
urllib.request.urlopen(req,context=context)

Create unverified https context in SSL

import ssl
ssl._create_default_https_context = ssl._create_unverified_context
urllib2.urlopen(“https://google.com”).read()

Use requests module and set ssl verify to false

requests.get(url, headers=Hostreferer,verify=False)

Update SSL certificate with PIP

we can also update our SSL certificate With PIP.  All we would have to do is  to update our SSL certificate directory with the following piece of code: pip install –upgrade certifi

What this command does is update our system’s SSL certificate directory.

Reference:

Understanding SSL certificates

Check SSL Certificate Chain with OpenSSL Examples

5 ways to check SSL Certificate

#python #ssl #proxy #python-requests

#питон #ssl #прокси #python-запросы

Вопрос:

При отправке запроса с аутентификацией я получаю requests.exceptions .Ошибка SSLError, которую вы можете увидеть ниже.

 proxies = { 'https' : "http://user:pass@ip:port/" } 

url = "https://httpbin.org/ip"

numberResponse = requests.get(url,proxies=proxies).text

print(numberResponse)
 

Запросы.исключения.Ошибка SSLError

 Traceback (most recent call last):
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 696, in urlopen       
    self._prepare_proxy(conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 496, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 428, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 472, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 1040, in _create
    self.do_handshake()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilretry.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.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)')))
 

Итак, я устал проверять =False в качестве одного из параметров requests.get(), но затем получаю requests.exceptions.Ошибка ProxyError, которую вы можете увидеть ниже :

 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)
 

Запросы.исключения.Ошибка ProxyError

 Traceback (most recent call last):
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 696, in urlopen       
    self._prepare_proxy(conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 496, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 428, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 472, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 1040, in _create
    self.do_handshake()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilretry.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.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')))
 

Я устал искать ответ на каждый вопрос, но, похоже, ничего не работает. Я не могу отправить запрос с помощью прокси с
аутентификацией. Есть идеи?

Ответ №1:

Проблема, скорее всего, не в аутентификации. К сожалению, вы не предоставляете подробную информацию о конфигурации прокси и URL, который вы используете для прокси. Единственное, что вы предоставляете, это:

 proxies = { 'https' : eampleIpWithAuth } 
 

Основываясь на ссылке _connect_tls_proxy в stacktrace eampleIpWithAuth , очень вероятно, что-то вроде https://... , т.Е. Вы пытаетесь получить доступ к самому прокси через HTTPS. Обратите внимание, что доступ к прокси через HTTPS отличается от использования HTTP-прокси для HTTPS. При доступе к URL-адресу HTTPS через прокси-сервер HTTPS по сути выполняется двойное шифрование прокси-сервера:

 client --- [HTTPS wrapped inside HTTPS] --- proxy --- [HTTPS] --- server
 

В то время как с URL-адресом HTTPS через «обычный» HTTP-прокси существует только одно шифрование, т. Е. Оно выглядит (упрощенно) следующим образом:

 client --- [HTTPS wrapped inside HTTP]  --- proxy --- [HTTPS] --- server
 

Очень вероятно, что прокси, который вы хотите использовать, — это обычный HTTP-прокси, а не HTTPS-прокси. На самом деле это самый распространенный случай.

Ошибка возникает, поскольку прокси-сервер не может говорить по протоколу TLS, но получает доступ по протоколу TLS. Исправление заключается в использовании http://proxy , а не https://proxy в качестве адреса прокси. Обратите внимание, что последнее работало в более старых версиях Python, поскольку прокси через HTTPS не поддерживался, а значение https:// для протокола обрабатывалось так же, как http:// .

Ответ №2:

У меня была аналогичная проблема с моим скриптом в версии python 3.9. Когда я пытаюсь получить некоторые данные с веб-сервера, у меня было исключение, подобное вашему:

 urllib3.exceptions.MaxRetryError
 

Просто добавьте эту строку для настройки ваших запросов

 import requests
import urllib3
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL:@SECLEVEL=1'
 

Я надеюсь, это поможет вам решить вашу проблему

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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 696, in urlopen       
    self._prepare_proxy(conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 496, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 428, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 472, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 1040, in _create
    self.do_handshake()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilretry.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 696, in urlopen       
    self._prepare_proxy(conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py", line 496, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 428, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py", line 472, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.py", line 1040, in _create
    self.do_handshake()
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libssl.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilretry.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:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersK_YukAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.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?

Advertisement

Answer

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://.

1 People found this is helpful

Понравилась статья? Поделить с друзьями:
  • Python print encode error
  • Python pptx как изменить шрифт
  • Python pickle memory error
  • Python parameter error
  • Python pandas memory error