requests.get doesn't care about my proxies [http / https / sock4 / sock5]

Viewed 276

I want to test the working state of proxies contained in a list. Proxies can be HTTP/HTTPS or Socks4/socks5 type and they are formatted this way :

104.207.147.141:8080
103.216.51.210:8191
3.9.34.151:3128
191.232.214.74:8080
socks4://138.59.143.37:57669
socks4://185.169.181.24:4145
socks4://45.115.112.214:40308

to test them I realize a request on the site http://ifconfig.me/ip which sends me back my IP if it was reached correctly. :

def tester(proxies, ip, ref_IPs):
  whitelist = []

  for proxy in range(0, len(proxies), 1):
    print(proxies[proxy])
    rep = requests.get("http://ifconfig.me/ip", {'http': proxies[proxy], 'https': proxies[proxy]}, timeout=1)
    if rep.text == ip:
        whitelist.append(ref_IPs[proxy])
    fileCreator(cleaner(whitelist, 1))

the whole thing works well, but the proxies don't seem to have any influence on the request. Proxies are therefore all concidered as functional regardless of the address.

191.232.214.74:8080 -> work
socks4://138.59.143.37:57669 -> work
AAA.k4.yy.43:B345 -> work

can you explain to me why?

1 Answers

requests.get have the following prototype:

requests.get(url, params=None, **kwargs)

What you need is the parameter 'proxies' in the kwargs so your request must looks like that:

rep = requests.get("http://ifconfig.me/ip", proxies={'http': proxies[proxy], 'https': proxies[proxy]}, timeout=1)
Related