Why use proxies with Python requests?

Python Requests is the most popular HTTP library for Python. Combined with DataSea proxies, you can scrape websites at scale, spread requests across many IPs, and access geo-restricted content with fewer blocks.

Prerequisites

  • Python 3.7 or higher installed
  • pip package manager
  • DataSea account with proxy credentials
  • Basic Python knowledge

Setup guide

  1. 01

    Get your DataSea credentials

    Sign in to your DataSea dashboard and copy your proxy username and password from the Credentials section.

    text
    # DataSea Proxy Configuration
    Proxy Host: pr.datasea.io
    HTTP Port: 7011 (for http:// and https:// websites)
    HTTPS-to-proxy Port: 7010 (TLS between your client and the proxy)
    
    # Your credentials (from dashboard)
    Username: your_proxy_username
    Password: your_16_char_password
    
    # Proxy URL format
    http://username:password@pr.datasea.io:7011
    
    # With country targeting
    http://username_country-UnitedStates:password@pr.datasea.io:7011
    
    # With sticky session
    http://username_session-abc123:password@pr.datasea.io:7011
  2. 02

    Install Python requests

    Install the requests library using pip if you haven't already.

    bash
    pip install requests
  3. 03

    Basic proxy configuration

    Configure requests to use DataSea proxies for your HTTP requests.

    python
    import requests
    
    # DataSea proxy credentials
    PROXY_USER = "your_username"
    PROXY_PASS = "your_password"
    
    # Configure proxy
    proxies = {
        'http': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
        'https': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
    }
    
    # Make a request through the proxy
    response = requests.get(
        'https://api.ipify.org?format=json',
        proxies=proxies,
        timeout=30
    )
    
    print(f"Your proxy IP: {response.json()['ip']}")
  4. 04

    Test your connection

    Verify the proxy is working by checking your IP address.

    python
    import requests
    
    PROXY_USER = "your_username"
    PROXY_PASS = "your_password"
    
    proxies = {
        'http': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
        'https': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
    }
    
    # Test the proxy connection
    try:
        response = requests.get(
            'https://httpbin.org/ip',
            proxies=proxies,
            timeout=30
        )
        print(f"Success! Proxy IP: {response.json()['origin']}")
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")

Key features

Global coverage

Access 195+ countries with residential, datacenter, ISP, and mobile proxies.

Automatic rotation

Get a new IP with each request or use sticky sessions for consistent IPs.

High performance

Low latency connections optimized for Python applications.

Simple authentication

Username/password authentication that works seamlessly with requests.

Usage analytics

Track bandwidth usage and success rates in your dashboard.

Easy geo-targeting

Target specific countries by adding parameters to your username.

Common use cases

Web scraping with rotating proxies

Scrape websites at scale without getting blocked by rotating IPs on each request.

python
import requests
from bs4 import BeautifulSoup

PROXY_USER = "your_username"
PROXY_PASS = "your_password"

proxies = {
    'http': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
    'https': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
}

# Scrape multiple pages with rotating IPs
urls = [f"https://example.com/page/{i}" for i in range(1, 100)]

for url in urls:
    response = requests.get(url, proxies=proxies, timeout=30)
    soup = BeautifulSoup(response.content, 'html.parser')

    # Process the page...
    title = soup.find('title').text
    print(f"Scraped: {title}")

Geo-targeted requests

Access content from specific countries by adding _country- and a country code or name to your username.

python
import requests

PROXY_PASS = "your_password"

# Target different countries
countries = ['US', 'GB', 'DE', 'JP', 'AU']

for country in countries:
    # Add country to username
    proxy_user = f"your_username_country-{country}"

    proxies = {
        'http': f'http://{proxy_user}:{PROXY_PASS}@pr.datasea.io:7011',
        'https': f'http://{proxy_user}:{PROXY_PASS}@pr.datasea.io:7011',
    }

    response = requests.get(
        'https://httpbin.org/ip',
        proxies=proxies,
        timeout=30
    )

    print(f"{country}: {response.json()['origin']}")

Sticky sessions for login

Maintain the same IP across multiple requests using session IDs.

python
import requests

PROXY_PASS = "your_password"
SESSION_ID = "login123"  # 1-32 letters or digits

# Create sticky session proxy (same IP for all requests)
proxy_user = f"your_username_country-UnitedStates_session-{SESSION_ID}"

proxies = {
    'http': f'http://{proxy_user}:{PROXY_PASS}@pr.datasea.io:7011',
    'https': f'http://{proxy_user}:{PROXY_PASS}@pr.datasea.io:7011',
}

# Use requests Session for cookies
session = requests.Session()
session.proxies = proxies

# Login and browse with same IP
session.post('https://example.com/login', data={
    'username': 'user',
    'password': 'pass'
})

# All subsequent requests use the same IP
response = session.get('https://example.com/dashboard')
print(response.text)

Concurrent requests with threading

Speed up scraping with multiple concurrent requests.

python
import requests
from concurrent.futures import ThreadPoolExecutor

PROXY_USER = "your_username"
PROXY_PASS = "your_password"

proxies = {
    'http': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
    'https': f'http://{PROXY_USER}:{PROXY_PASS}@pr.datasea.io:7011',
}

def fetch_url(url):
    try:
        response = requests.get(url, proxies=proxies, timeout=30)
        return {'url': url, 'status': response.status_code}
    except Exception as e:
        return {'url': url, 'error': str(e)}

urls = [f"https://example.com/page/{i}" for i in range(100)]

# Fetch 10 URLs concurrently
with ThreadPoolExecutor(max_workers=10) as executor:
    results = list(executor.map(fetch_url, urls))

for result in results:
    print(result)

Troubleshooting

Connection Timeout

Solution: Increase the timeout value and ensure your credentials are correct.

python
# Increase timeout for slow connections
response = requests.get(
    url,
    proxies=proxies,
    timeout=60  # 60 seconds
)

# Or use separate connect/read timeouts
response = requests.get(
    url,
    proxies=proxies,
    timeout=(10, 30)  # 10s connect, 30s read
)

ProxyError: Cannot connect to proxy

Solution: Verify your proxy credentials and ensure you're using the correct port (7011 for HTTP).

python
# Correct proxy format
proxies = {
    'http': 'http://username:password@pr.datasea.io:7011',
    'https': 'http://username:password@pr.datasea.io:7011',
}

# Common mistake: using wrong port
# WRONG: pr.datasea.io:80
# CORRECT: pr.datasea.io:7011

SSL Certificate Errors

Solution: The proxy handles SSL. If you still see errors, you can disable verification for testing.

python
# For testing only - not recommended for production
response = requests.get(
    url,
    proxies=proxies,
    verify=False  # Disable SSL verification
)

# Better: Use proper SSL handling
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Rate Limiting / 429 Errors

Solution: Add delays between requests and implement retry logic.

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

# Setup retry strategy
retry_strategy = Retry(
    total=3,
    backoff_factor=1,
    status_forcelist=[429, 500, 502, 503, 504]
)

adapter = HTTPAdapter(max_retries=retry_strategy)
session = requests.Session()
session.mount("http://", adapter)
session.mount("https://", adapter)
session.proxies = proxies

# Add delay between requests
for url in urls:
    response = session.get(url, timeout=30)
    time.sleep(1)  # 1 second delay

Get started with industry‑leading proxy access

Connect to 150M+ real IPs in seconds. Built for scale, privacy, and performance. Free trial available.