How to fix OSError('Tunnel connection failed: 407 Proxy Authentication Required')

452 views Asked by At

How do I solve the problem? If I use a proxy I get: 407 Proxy Authentication Required.

If I remove the proxy, I get: status_code = 200.

I want to use a proxy service, I bought 1 IP and I want to use a static IP.

I am letting it into the colab for testing.

I use iproyal.com STATIC RESIDENTIAL PROXIES. I want to repeat the requests in 5 seconds and use two or three static IPs.

import requests
from requests.auth import HTTPProxyAuth

json_url = "https://www.marktplaats.nl/lrp/api/....."

headers = requests.utils.default_headers()
headers.update({
        'User-Agent': 'Mozilla/6.0 (Macintosh; Intel Mac OS X 10_10_1) 
         AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
        })
#proxy_string = '//30.30.30.30:12345'
s = requests.Session()
#s.proxies = {"http": proxy_string , "https": proxy_string}
#s.auth = HTTPProxyAuth('user','pass')
#s.trust_env=False
r = s.get(json_url, headers=headers)
print(r.status_code)

Full error:

  ---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py in urlopen(self, 
method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, 
release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    775                 try:
--> 776                     self._prepare_proxy(conn)
    777                 except (BaseSSLError, OSError, SocketTimeout) as e:

10 frames
OSError: Tunnel connection failed: 407 Proxy Authentication Required

The above exception was the direct cause of the following exception:

ProxyError                                Traceback (most recent call last)
ProxyError: ('Unable to connect to proxy', OSError('Tunnel connection failed: 407 Proxy 
Authentication Required'))

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
MaxRetryError: HTTPSConnectionPool(host='www.marktplaats.nl', port=443): Max retries 
exceeded with url: /lrp/api/search? 

  =91&limit=99&offset=0&query=transit&searchInTitleAndDescription=true&sortBy=SORT 
 _INDEX&sortOrder=DECREASING&viewOptions=list-view (Caused by ProxyError('Unable to 
  connect 
 to proxy', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))

 During handling of the above exception, another exception occurred:

 ProxyError                                Traceback (most recent call last)
 /usr/local/lib/python3.10/dist-packages/requests/adapters.py in send(self, request, 
 stream, timeout, verify, cert, proxies)
  511 
  512             if isinstance(e.reason, _ProxyError):
 --> 513                 raise ProxyError(e, request=request)
  514 
  515             if isinstance(e.reason, _SSLError):

  ProxyError: HTTPSConnectionPool(host='www.marktplaats.nl', port=443): Max retries 
  exceeded with url: /lrp/api/search? 
  91&limit=99&offset=0&query=transit&searchInTitleAndDescription=true&sortBy=SORT 
  _INDEX&sortOrder=DECREASING&viewOptions=list-view (Caused by ProxyError('Unable to 
  connect 
 to proxy', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))
0

There are 0 answers