Python Request Returns OSError 403 Forbidden with Proxies on Ubuntu

192 views Asked by At

I've spent countless hours trying to resolve the below issue and whilst I've narrowed down the issue, I've yet to find a solution.

The code runs fine on Windows 10 with no errors, however, when running on Ubuntu around 1/50-100 requests produce the following error:

HTTPSConnectionPool(host='api.my-ip.io/ip', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

The code I am using for testing:

import requests
from time import sleep

url = "https://api.my-ip.io/ip"
proxyList = [
'http://user:pass@ip:port',
'http://user:pass@ip:port',
'http://user:pass@ip:port'
]

def startTest():
    while True:
        for proxy in proxyList:
            r = requests.get(url, proxies={'https':proxy}, timeout=20)
            print(f"[Status: {r.status_code}] - [Resp: {r.text}] - [Proxy: {proxy}]")
            sleep(1)
startTest()

To clarify, here are some further details:

  • This error seems persistent with several websites/apis I've tried so doesn't seem to be the site
  • I've tried running both Windows & Linux on the same local IP to eliminate my server being the issue
  • Both Windows & Linux were running the same Python version
  • It's not a select bad proxy in the list which produces the error

The proxies are paid for (which is why I've redacted that info). I do not have access to the configuration, however, besides headers which I've already tried spoofing (maybe badly), I cannot understand what the difference would be with running the code on Windows vs Linux on the same network.

Any help would be appreciated.

0

There are 0 answers