Skip to content
Back to Blog

Developer Guides

How to Set Up a Rotating Proxy in Python, Node.js, and Bash (2025 Guide)

ZentisLabs Team12 min read

Setting up rotating proxies is essential for web scraping, data collection, and automation at scale. In this guide, we'll walk through complete implementations in Python, Node.js, and Bash - all using ZentisLabs's rotating residential proxy gateway.

Prerequisites

  • A ZentisLabs account with an active residential proxy plan
  • Your API credentials (username + password) from the dashboard
  • Python 3.8+, Node.js 18+, or Bash with curl installed

Python Setup

Using the requests library with ZentisLabs's rotating gateway:

python
import requests
proxy_url = "http://USER:PASS@basic.resi.zentislabs.com:12321"
proxies = {"http": proxy_url, "https": proxy_url}
# Each request gets a different IP
for i in range(5):
r = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=10)
print(f"Request {i+1}: {r.json()['origin']}")
# Sticky IP (same IP for 10 minutes): paste a sticky line exactly as generated
# in the dashboard or API. Generated sticky lines are pinned to one gateway node.
host, port, user, password = "NODE_IP:12321:USER:PASS_country-us_session-abc123_lifetime-10m".split(":")
sticky_proxy = f"http://{user}:{password}@{host}:{port}"
session = requests.Session()
session.proxies = {"http": sticky_proxy, "https": sticky_proxy}
for i in range(3):
r = session.get("https://httpbin.org/ip", timeout=10)
print(f"Sticky {i+1}: {r.json()['origin']}") # Same IP each time

Node.js Setup

javascript
const axios = require('axios');
const { HttpsProxyAgent } = require('https-proxy-agent');
const agent = new HttpsProxyAgent('http://USER:PASS@basic.resi.zentislabs.com:12321');
async function fetchWithProxy() {
const { data } = await axios.get('https://httpbin.org/ip', {
httpsAgent: agent,
proxy: false,
timeout: 10000,
});
console.log('IP:', data.origin);
}
// Rotate through 5 requests
(async () => {
for (let i = 0; i < 5; i++) {
await fetchWithProxy();
}
})();

Bash / cURL Setup

bash
# Simple rotating proxy request
curl -x http://USER:PASS@basic.resi.zentislabs.com:12321 https://httpbin.org/ip
# Loop with different IPs
for i in {1..5}; do
echo "Request $i:"
curl -s -x http://USER:PASS@basic.resi.zentislabs.com:12321 https://httpbin.org/ip
echo ""
done
# With geo-targeting (US only)
curl -x http://USER:PASS_country-us@basic.resi.zentislabs.com:12321 https://httpbin.org/ip

Pro tip: Use sticky sessions when scraping multi-page flows (login → navigate → scrape). Generate sticky lines in the dashboard or API and use them exactly as generated: each carries its own _session-XXXX ID and is pinned to one gateway node, so your IP holds for the whole flow.

Geo-Targeting

ZentisLabs supports country, state, and city-level targeting. On the Basic and Light plans, append targeting params to your password (a city always follows its state):

text
Country: PASS_country-us
State: PASS_country-us_state-california
City: PASS_country-de_state-berlin-city-berlin

Error Handling

Always implement retries with exponential backoff. Proxy connections can occasionally timeout - this is normal for residential IPs.

python
import time
import requests
from requests.exceptions import ProxyError, Timeout
def fetch_with_retry(url, proxies, max_retries=3):
for attempt in range(max_retries):
try:
return requests.get(url, proxies=proxies, timeout=15)
except (ProxyError, Timeout) as e:
wait = 2 ** attempt
print(f"Retry {attempt+1} in {wait}s: {e}")
time.sleep(wait)
raise Exception("Max retries exceeded")

Ready to get started?

Try ZentisLabs free - 100MB residential bandwidth included.