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.
Sign in to your DataSea dashboard and copy your proxy username and password from the Credentials section.
# 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:7011Install the requests library using pip if you haven't already.
pip install requestsConfigure requests to use DataSea proxies for your HTTP requests.
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']}")Verify the proxy is working by checking your IP address.
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}")Access 195+ countries with residential, datacenter, ISP, and mobile proxies.
Get a new IP with each request or use sticky sessions for consistent IPs.
Low latency connections optimized for Python applications.
Username/password authentication that works seamlessly with requests.
Track bandwidth usage and success rates in your dashboard.
Target specific countries by adding parameters to your username.
Scrape websites at scale without getting blocked by rotating IPs on each request.
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}")Access content from specific countries by adding _country- and a country code or name to your username.
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']}")Maintain the same IP across multiple requests using session IDs.
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)Speed up scraping with multiple concurrent requests.
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)Solution: Increase the timeout value and ensure your credentials are correct.
# 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
)Solution: Verify your proxy credentials and ensure you're using the correct port (7011 for HTTP).
# 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:7011Solution: The proxy handles SSL. If you still see errors, you can disable verification for testing.
# 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)Solution: Add delays between requests and implement retry logic.
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 delayConnect to 150M+ real IPs in seconds. Built for scale, privacy, and performance. Free trial available.