Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im getting this error when I try to use SOCKS4 proxies with the Module 'requests' in python:

```
requests.exceptions.ConnectionError:SOCKSHTTPSConnectionPool(host='www.Example.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x0000029BDEB0B550>: Failed to establish a new connection: Connection closed unexpectedly'))```
```

My question is:
Why am i getting this error
and how can i fix it.


This is my script:
````````try:
            global x
            x += 1
            proxyfile4 = open("socks4_proxies.txt", "r")
            socks4 = proxyfile4.readlines()
            proxies = {
                'https': 'socks4://' + socks4[x],
            }
            url = (socks4[x])
            r = requests.get("https://google.com", proxies=proxies, timeout=5)
           lif r.status_code == 200:
                a += 1
                rr()
                valid = open("Socks4_Alive.txt", "a+")
         except TimeoutError:
            e += 1
            rr()
         except ConnectionError:
            e += 1
            rr()

         except IndexError:
            print(Fore.LIGHTGREEN_EX + "Done")<pre>

What I have tried:

I have tryed to use other/better proxies.
Posted
Updated 7-Jun-21 13:35pm
Comments
Richard MacCutchan 9-Feb-21 4:24am    
Try using that URL in your browser to see what happens.
20212a 9-Feb-21 13:50pm    
Some things to try, https://stackoverflow.com/questions/23013220/max-retries-exceeded-with-url-in-requests

1 solution

change: https
proxies = {
'https': 'socks4://' + socks4[x],
}
to: http
proxies = {
'http': 'socks4://' + socks4[x],
}
 
Share this answer
 
Comments
Richard Deeming 8-Jun-21 4:24am    
The OP was making an HTTPS request. Changing the proxy so that it only applies to HTTP requests will not solve their problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900