Python Forum
Python Request's Proxies not working.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Request's Proxies not working.
#1
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?
Reply
#2
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')}
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Scraping a page with log in data (security, proxies) iamaghost 0 589 Mar-27-2021, 02:56 PM
Last Post: iamaghost
Question Telegram bot - Problem with proxies and web server NoNameoN 1 627 Oct-16-2020, 05:37 PM
Last Post: NoNameoN
  Python + request from specific website - please help hoff1022 8 1,838 Feb-14-2019, 06:52 PM
Last Post: buran
  Python handling Apache Request harzsr 3 1,652 Nov-16-2018, 04:36 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020