Python Requests

Python Requests

The most popular Python HTTP library with simple proxy configuration for web requests.

Python Requests

Python Requests is the most popular HTTP library in Python. It makes sending HTTP requests simple and supports proxy configuration out of the box.

Setting Up HypeProxy.io with Python Requests

HTTP Proxy

import requests

proxies = {
    'http': 'http://username:password@fr.hypeproxy.host:port',
    'https': 'http://username:password@fr.hypeproxy.host:port',
}

response = requests.get('https://api.ipify.org?format=json', proxies=proxies)
print(response.json())

SOCKS5 Proxy

import requests

proxies = {
    'http': 'socks5://username:password@fr.hypeproxy.host:port',
    'https': 'socks5://username:password@fr.hypeproxy.host:port',
}

response = requests.get('https://api.ipify.org?format=json', proxies=proxies)
print(response.json())

With Session (Reusable)

import requests

session = requests.Session()
session.proxies = {
    'http': 'http://username:password@fr.hypeproxy.host:port',
    'https': 'http://username:password@fr.hypeproxy.host:port',
}

# All requests through the session use the proxy
response = session.get('https://example.com')

With IP Rotation via API

import requests
import time

API_TOKEN = 'YOUR_API_TOKEN'
PROXY_ID = 'YOUR_PROXY_ID'

# Rotate IP
requests.get(
    f'https://api.hypeproxy.io/Utils/DirectRenewIp/{PROXY_ID}',
    headers={'Authorization': f'Bearer {API_TOKEN}'}
)
time.sleep(5)

# Make request through proxy
proxies = {
    'http': 'http://username:password@fr.hypeproxy.host:port',
    'https': 'http://username:password@fr.hypeproxy.host:port',
}
response = requests.get('https://example.com', proxies=proxies)

Tips

  • Use requests.Session() to reuse proxy settings across multiple requests.
  • For SOCKS5 support, install pip install requests[socks].
  • Add timeout parameter to avoid hanging requests: requests.get(url, proxies=proxies, timeout=30).
  • Use try/except blocks to handle proxy connection errors gracefully.

Was this article helpful?