Python Forum

Full Version: Python Request's Proxies not working.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to use requests with proxies, but it only shows my local IP

Here's my test code.

#!/usr/bin/python3

import requests
import random
impo


proxies = [
    "167.172.248.53:3128",
    "194.226.34.132:5555",
    "203.202.245.62:80",
    "141.0.70.211:8080",
    "118.69.50.155:80",
    "201.55.164.177:3128",
    "51.15.166.107:3128",
    "91.205.218.64:80",
    "128.199.237.57:8080",
]


def get_session(proxies):
    session = requests.Session()
    proxy = random.choice(proxies)
    session.proxies = {"http://": proxy, "https://": proxy}
    return session, proxy


for i in range(5):
    s, proxy = get_session(proxies)
    try:
        print(
            f"Proxying through {proxy}:",
            s.get("http://icanhazip.com", timeout=1.5).text.strip(),
        )
    except Exception as e:
        continue
I

Proxying through 141.0.70.211:8080: 51.25x.xxx.193
Proxying through 201.55.164.177:3128: 51.25x.xxx.193
Proxying through 91.205.218.64:80: 51.25x.xxx.193
Proxying through 141.0.70.211:8080: 51.25x.xxx.193
Proxying through 51.15.166.107:3128: 51.25x.xxx.193
Any idea's on why this is not working?
try adding scheme to url, as per the docs:
Quote:Note that proxy URLs must include the scheme.

session.proxies = {scheme:f'{scheme}://{proxy}' for scheme in ('http', 'https')}