Python Requests

This guide explains how to use Evomi proxies with the Python requests library, the most popular HTTP client for Python. It covers HTTP and SOCKS5 proxies, session-based usage, and error handling.

Prerequisites

  • Python 3.8+ installed
  • Your Evomi proxy credentials (username and password)

Installation

pip install requests

For SOCKS5 proxy support:

pip install "requests[socks]"

Basic Usage

HTTP Proxy

import requests

proxy_user = "your_username"
proxy_pass = "your_password_session-anychars_mode-speed"
proxy_url = f"http://{proxy_user}:{proxy_pass}@rp.evomi.com:1000"

proxies = {
    "http": proxy_url,
    "https": proxy_url,
}

response = requests.get("https://ip.evomi.com/s", proxies=proxies, timeout=15)
print("Proxy IP:", response.text.strip())

SOCKS5 Proxy

import requests

proxy_user = "your_username"
proxy_pass = "your_password_session-anychars_mode-speed"
proxy_url = f"socks5h://{proxy_user}:{proxy_pass}@rp.evomi.com:1002"

proxies = {
    "http": proxy_url,
    "https": proxy_url,
}

response = requests.get("https://ip.evomi.com/s", proxies=proxies, timeout=15)
print("Proxy IP:", response.text.strip())

The socks5h:// scheme routes DNS resolution through the proxy server, preventing DNS leaks. Use socks5:// if you want local DNS resolution.

Replace your_username and your_password with your actual Evomi credentials.

Using Sessions (Recommended)

For multiple requests, use a Session object. This reuses the underlying TCP connection for better performance and lets you set the proxy once:

import requests

proxy_user = "your_username"
proxy_pass = "your_password_session-anychars_mode-speed"
proxy_url = f"http://{proxy_user}:{proxy_pass}@rp.evomi.com:1000"

session = requests.Session()
session.proxies.update({
    "http": proxy_url,
    "https": proxy_url,
})
session.headers.update({
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
})

response = session.get("https://ip.evomi.com/s", timeout=15)
print("Proxy IP:", response.text.strip())

response = session.get("https://example.com", timeout=15)
print("Status:", response.status_code)

Error Handling

import requests

proxy_url = "http://your_username:[email protected]:1000"
proxies = {"http": proxy_url, "https": proxy_url}

try:
    response = requests.get("https://ip.evomi.com/s", proxies=proxies, timeout=15)
    response.raise_for_status()
    print("Proxy IP:", response.text.strip())
except requests.exceptions.ProxyError as e:
    print(f"Proxy connection failed: {e}")
except requests.exceptions.Timeout:
    print("Request timed out")
except requests.exceptions.HTTPError as e:
    print(f"HTTP error: {e}")
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")

Retries with Backoff

For production scripts, add automatic retries:

import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

proxy_url = "http://your_username:[email protected]:1000"

session = requests.Session()
session.proxies.update({"http": proxy_url, "https": proxy_url})

retry_strategy = Retry(
    total=3,
    backoff_factor=1,
    status_forcelist=[429, 500, 502, 503, 504],
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("http://", adapter)
session.mount("https://", adapter)

response = session.get("https://ip.evomi.com/s", timeout=15)
print("Proxy IP:", response.text.strip())

Evomi Proxy Endpoints

Proxy Type HTTP HTTPS SOCKS5
Residential rp.evomi.com:1000 rp.evomi.com:1001 rp.evomi.com:1002
Mobile mp.evomi.com:3000 mp.evomi.com:3001 mp.evomi.com:3002
Datacenter dcp.evomi.com:2000 dcp.evomi.com:2001 dcp.evomi.com:2002

Tips and Troubleshooting

  • Credentials: Double-check your username and password. The password format is your_password_session-anychars_mode-speed.
  • Special characters: If your password contains @, :, or other special characters, URL-encode them with urllib.parse.quote():
    from urllib.parse import quote
    proxy_url = f"http://{quote(user)}:{quote(password)}@rp.evomi.com:1000"
  • Timeouts: Always set a timeout to avoid hanging indefinitely. Use a tuple for separate connect/read timeouts: timeout=(5, 30).
  • SOCKS5 dependency: If you get MissingSchema or MissingSocksModule errors, make sure you installed requests[socks].
  • Environment variables: You can set proxies globally via environment variables (HTTP_PROXY, HTTPS_PROXY), but use session.trust_env = False if you want your code to ignore them.
  • SSL verification: Avoid verify=False in production. If you see SSL errors, update your system CA certificates.