Datacenter Proxies Code Examples
Code samples for connecting to BytesFlows Datacenter Proxies in Python, Node.js, Go, and cURL.
Datacenter Proxies Code Examples
Production-ready integration snippets for common programming languages and frameworks.
cURL
Rotating Mode (HTTP)
curl -x http://u-username:password@p1.bytesflows.com:8001 https://ipinfo.io/json
Country-Specific Sticky Session (SOCKS5)
curl -x socks5://u-username-loc-US-s-session001-t-30:password@p1.bytesflows.com:8001 https://ipinfo.io/json
Python
1. Using Requests
import requests
proxy_url = "http://u-username-loc-US-s-session1-t-30:password@p1.bytesflows.com:8001"
proxies = {
"http": proxy_url,
"https": proxy_url,
}
try:
response = requests.get(
"https://ipinfo.io/json",
proxies=proxies,
timeout=15,
)
print("Status:", response.status_code)
print("IP Data:", response.json())
except Exception as e:
print("Request failed:", e)
2. Async Concurrency with Aiohttp
import aiohttp
import asyncio
PROXY_URL = "http://u-username-loc-US:password@p1.bytesflows.com:8001"
async def fetch(session, url):
async with session.get(url, proxy=PROXY_URL, timeout=10) as resp:
return await resp.json()
async def main():
async with aiohttp.ClientSession() as session:
tasks = [fetch(session, "https://ipinfo.io/json") for _ in range(5)]
results = await asyncio.gather(*tasks)
for res in results:
print("Concurrent IP:", res.get("ip"))
if __name__ == "__main__":
asyncio.run(main())
Node.js
1. Using Axios
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
const proxyUrl = 'http://u-username-loc-US-s-sess1-t-30:password@p1.bytesflows.com:8001';
const httpsAgent = new HttpsProxyAgent(proxyUrl);
async function testProxy() {
try {
const { data } = await axios.get('https://ipinfo.io/json', {
httpsAgent,
timeout: 10000,
});
console.log('Proxy IP Data:', data);
} catch (error) {
console.error('Request Error:', error.message);
}
}
testProxy();
2. Playwright Headless Browser
import { chromium } from 'playwright';
(async () => {
const browser = await chromium.launch({
proxy: {
server: 'http://p1.bytesflows.com:8001',
username: 'u-username-loc-US-s-browser1-t-60',
password: 'password',
},
});
const page = await browser.newPage();
await page.goto('https://ipinfo.io/json');
const content = await page.textContent('body');
console.log('Browser IP details:', content);
await browser.close();
})();
Go
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func main() {
proxyStr := "http://u-username-loc-US-s-go1-t-30:password@p1.bytesflows.com:8001"
proxyURL, err := url.Parse(proxyStr)
if err != nil {
panic(err)
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
},
Timeout: 15 * time.Second,
}
resp, err := client.Get("https://ipinfo.io/json")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Printf("Response: %s\n", string(body))
}