Proxys in Python und Node.js verwenden
Codebeispiele für requests, httpx, aiohttp, Node.js fetch und axios — mit HTTP und SOCKS5, Authentifizierung und IP-Rotation.
Ob Scraper, Bot oder Automatisierung — ein Proxy ist in wenigen Zeilen eingebunden. Die Daten im Format host:port:login:password finden Sie unter „Meine Proxys“.
Python: requests
import requests
proxy = "http://login:password@host:port"
r = requests.get("https://ipinfo.io/json", proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.json()["ip"])
Für SOCKS5: pip install requests[socks] und das Schema socks5h://.
Python: httpx und aiohttp
import httpx
async with httpx.AsyncClient(proxy="http://login:password@host:port", timeout=30) as client:
r = await client.get("https://ipinfo.io/json")
import aiohttp
async with aiohttp.ClientSession() as s:
async with s.get("https://ipinfo.io/json", proxy="http://login:password@host:port") as r:
print(await r.json())
Node.js: undici / fetch
import { ProxyAgent, fetch } from 'undici';
const agent = new ProxyAgent('http://login:password@host:port');
const res = await fetch('https://ipinfo.io/json', { dispatcher: agent });
Node.js: axios
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent('http://login:password@host:port');
const { data } = await axios.get('https://ipinfo.io/json', { httpsAgent: agent, proxy: false });
Für SOCKS5 in Node.js: Paket socks-proxy-agent.
IP-Rotation
Private Proxys: zufällig oder reihum aus der Liste wählen. Residential und Mobil: die IP wechselt automatisch; für eine feste IP login-session-ab12cd-time-10 (Details).
Proxys per Code kaufen und verlängern: ProxyZen-API.
Häufige Fehler
- 407 — falsche Zugangsdaten.
- Timeout — falscher Port; Residential und Mobil: HTTP 8080, SOCKS5 1080.
- SSL-Fehler — meist falsches Schema (
http://für HTTP-Proxys, auch bei HTTPS-Seiten).
ProxyZen testen
IPv4 und IPv6 ab $0.05, Residential und mobil pro GB. Sofortige Bereitstellung, HTTP(S) und SOCKS5.