Skip to content
Nefo

Requests

How to Use Residential Proxies with Python Requests

Pass a proxies dict to requests, add requests[socks] for SOCKS5, and use a Session with a session token when a workflow needs cookies and one IP to stay together.

Before you start

Nefo offers residential proxies in 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic consumes your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).

The requests library reads proxy URLs directly, so no extra dependency is needed for HTTP. For SOCKS5, install requests[socks].

  • Python 3.9+ with the requests library installed
  • requests[socks] installed if you want SOCKS5
  • A Nefo account with prepaid bandwidth
  • A username/password from /dashboard/generator
  • Your target country token

Python requests proxies dict example

Build the proxies dict and pass it to your call:

For SOCKS5, change the scheme and port: socks5h://USERNAME-country-us:[email protected]:11000. The socks5h scheme resolves DNS through the proxy. Swap the country token to target any of 227 countries.

shell
import requests

proxies = {
    'http': 'http://USERNAME-country-us:[email protected]:9000',
    'https': 'http://USERNAME-country-us:[email protected]:9000',
}

r = requests.get('https://api.ipify.org', proxies=proxies)
print(r.text)

Python requests rotating vs sticky proxies

Rotating sessions give a new residential IP per request: HTTP port 9000 or SOCKS5 port 11000. Ideal for spreading many small requests across exits.

Sticky sessions keep one IP from 1 minute up to 24 hours: HTTP port 10000 or SOCKS5 port 12000. Add a token like USERNAME-country-us-session-job5-lifetime-30 and reuse a requests.Session() to keep cookies and IP aligned for a stateful workflow.

Geo-targeting in the requests proxy username

Targeting is driven by username tokens: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username string changes between regions, keeping your code stable.

Fetch data lawfully, respect each site's terms of service, and stay within applicable law and reasonable request rates.

Frequently asked questions

Yes. Install requests[socks] (PySocks) to use socks5h URLs on port 11000 or 12000. Plain HTTP proxies on ports 9000 and 10000 need no extra package.

Start with 5 GB. Keep what you don't use.

Residential bandwidth from $0.53/GB that never expires. Card, PayPal, Apple Pay, Google Pay, Alipay and crypto.