pythonpython-requestsproxyproxies

Cant use proxy on python request


I have three versions that i tested: 3.10.2, 3.9.9 and 3.8.10 on different machines and even one online compiler. In all of them i did the following:

import requests
requests.get(url, proxies=proxies, headers=headers)

Testing in each parameter: url:

"https://www.icanhazip.com"
"http://www.icanhazip.com"

proxies:

{"https": "223.241.0.250:3000", "http": "223.241.0.250:3000"}
{"https": "223.241.0.250:3000", "http": "223.241.0.250:3000"}

headers:

{'User-Agent': 'Chrome'}
{"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"}

In all of them but the 3.10.2 I got this error:

ProxyError: HTTPSConnectionPool(host='www.icanhazip.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConn
ectionError('<urllib3.connection.HTTPSConnection object at 0x05694F40>: Failed to establish a new connection: [WinError 10060] A connection attempt failed beca
use the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')))

On the 3.10.2 i got:

InvalidURL: Proxy URL had no scheme, should start with http:// or https://

But when i tried to put the proxies like this: {"https": "223.241.0.250:3000", "http": "223.241.0.250:3000"} It didnt work and it just showed my normal ip.

What am I missing? A normal requests works just fine but when I add the proxies it just doesnt work. This code was working fine a while back and now outputs this error I cant figure out why.


Solution

  • Try adding a scheme in the proxy address

    {"https": "http://223.241.0.250:3000", "http": "http://223.241.0.250:3000"}
    {"https": "http://223.241.0.250:3000", "http": "http://223.241.0.250:3000"}