[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-en-using-proxies-in-python":3},{"success":4,"payload":5,"related":83,"errors":172},true,{"id":6,"slug":7,"title":8,"excerpt":9,"body_html":10,"meta_title":11,"meta_description":12,"canonical_url":13,"canonical_override":14,"og_title":15,"og_description":12,"og_image_url":16,"faq_json":17,"key_takeaways":33,"allow_index":4,"noindex_google_only":39,"allow_follow":4,"published_at":40,"updated_at":41,"content_updated_at":42,"featured_image_url":43,"featured_image_alt":14,"card_image_url":44,"reading_time_minutes":45,"author":46,"categories":50,"tags":57,"alternates":69,"locale_paths":70,"views":82},3,"using-proxies-in-python","Using Proxies in Python (Requests + ProxyHat SDK)","Learn how to use proxies in Python with the Requests library and ProxyHat SDK. Covers authentication, rotation, geo-targeting, error handling, and async scraping.","\u003Ch2>Why Use Proxies in Python?\u003C\u002Fh2>\n\u003Cp>Python dominates the data extraction landscape. Libraries like \u003Cstrong>Requests\u003C\u002Fstrong>, \u003Cstrong>httpx\u003C\u002Fstrong>, and \u003Cstrong>Scrapy\u003C\u002Fstrong> make HTTP calls trivial, but without proxies, your scripts hit IP bans within minutes. Using proxies in Python lets you rotate IP addresses, bypass geo-restrictions, and scale your scraping operations reliably.\u003C\u002Fp>\n\u003Cp>In this guide, you will learn how to integrate proxies into Python using the \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FProxyHatCom\u002Fpython-sdk\" rel=\"noopener noreferrer\">ProxyHat Python SDK\u003C\u002Fa> and the standard \u003Ccode>requests\u003C\u002Fcode> library. Every section includes copy-paste-ready code you can run immediately.\u003C\u002Fp>\n\u003Cp>Whether you are building a \u003Ca href=\"\u002Fuse-cases\u002Fweb-scraping\">web scraping pipeline\u003C\u002Fa>, monitoring \u003Ca href=\"\u002Fuse-cases\u002Fserp-tracking\">SERP results\u003C\u002Fa>, or collecting pricing data, this guide covers authentication, proxy rotation, geo-targeting, error handling, and production scaling.\u003C\u002Fp>\n\u003Ch2>Installation and Setup\u003C\u002Fh2>\n\u003Ch3>Installing the ProxyHat SDK and Requests\u003C\u002Fh3>\n\u003Cp>Install the ProxyHat Python SDK and the \u003Ccode>requests\u003C\u002Fcode> library using pip:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>pip install proxyhat requests\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>For async workflows, also install \u003Ccode>httpx\u003C\u002Fcode> and \u003Ccode>aiohttp\u003C\u002Fcode>:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>pip install httpx aiohttp\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Getting Your API Credentials\u003C\u002Fh3>\n\u003Cp>Sign up at \u003Ca href=\"\u002Fpricing\">ProxyHat\u003C\u002Fa> and retrieve your API key from the dashboard. You will need your \u003Cstrong>username\u003C\u002Fstrong> and password (or API key) for proxy authentication. Full authentication details are available in the \u003Ca href=\"https:\u002F\u002Fdocs.proxyhat.com\u002F\" rel=\"noopener noreferrer\">ProxyHat API documentation\u003C\u002Fa>.\u003C\u002Fp>\n\u003Ch2>Authentication and Basic Configuration\u003C\u002Fh2>\n\u003Ch3>Using the ProxyHat SDK\u003C\u002Fh3>\n\u003Cp>The SDK uses your API key to look up your sub-user credentials and builds a ready-to-use proxy URL; you send the requests with any HTTP client:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>from proxyhat import ProxyHat\nclient = ProxyHat(\n    api_key=\"your_api_key_here\"\n)\n# Test the setup: build a proxy URL for one of your active sub-users\nproxy_url = client.connection_url(country=\"us\")\nprint(proxy_url)\n# e.g. http:\u002F\u002FUSERNAME-country-us:PASSWORD@gate.proxyhat.com:8080\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Using Raw Proxy Credentials with Requests\u003C\u002Fh3>\n\u003Cp>If you prefer using \u003Ccode>requests\u003C\u002Fcode> directly, configure the proxy URL:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>import requests\nproxy_url = \"http:\u002F\u002Fusername:password@gate.proxyhat.com:8080\"\nproxies = {\n    \"http\": proxy_url,\n    \"https\": proxy_url,\n}\nresponse = requests.get(\n    \"https:\u002F\u002Fhttpbin.org\u002Fip\",\n    proxies=proxies,\n    timeout=30\n)\nprint(response.json())\n# {\"origin\": \"185.xxx.xxx.xxx\"}\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Simple GET Request with a Proxy\u003C\u002Fh2>\n\u003Cp>Here is a complete example that sends a GET request through a ProxyHat \u003Ca href=\"\u002Fproxy\u002Fresidential\">residential proxy\u003C\u002Fa>:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>import requests\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\n# Build a rotating residential proxy URL, then make a proxied GET request\nproxy = client.connection_url(country=\"us\")\nresponse = requests.get(\n    \"https:\u002F\u002Fhttpbin.org\u002Fip\",\n    proxies={\"http\": proxy, \"https\": proxy},\n    timeout=30\n)\nprint(f\"Status: {response.status_code}\")\nprint(f\"IP: {response.json()['origin']}\")\nprint(f\"Headers: {response.headers}\")\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Or with the standard \u003Ccode>requests\u003C\u002Fcode> library:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>import requests\nproxies = {\n    \"http\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n    \"https\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n}\nresponse = requests.get(\n    \"https:\u002F\u002Fexample.com\u002Fapi\u002Fdata\",\n    proxies=proxies,\n    timeout=30,\n    headers={\"User-Agent\": \"Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64)\"}\n)\nprint(response.status_code)\nprint(response.text[:500])\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Choosing the Right Proxy Type\u003C\u002Fh2>\n\u003Cp>ProxyHat offers three proxy types. Choose based on your use case. For a deeper comparison, read our guide on \u003Ca href=\"\u002Fblog\u002Fresidential-vs-datacenter-vs-mobile-proxies\">residential vs datacenter vs mobile proxies\u003C\u002Fa>.\u003C\u002Fp>\n\u003Ctable>\n\u003Ccaption>Choosing the Right Proxy Type\u003C\u002Fcaption>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>Type\u003C\u002Fth>\n\u003Cth>Best For\u003C\u002Fth>\n\u003Cth>Speed\u003C\u002Fth>\n\u003Cth>Detection Risk\u003C\u002Fth>\n\u003Cth>Cost\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>Residential\u003C\u002Ftd>\n\u003Ctd>Web scraping, SERP tracking\u003C\u002Ftd>\n\u003Ctd>Medium\u003C\u002Ftd>\n\u003Ctd>Very low\u003C\u002Ftd>\n\u003Ctd>Per GB\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Datacenter\u003C\u002Ftd>\n\u003Ctd>High-volume, speed-critical tasks\u003C\u002Ftd>\n\u003Ctd>Fast\u003C\u002Ftd>\n\u003Ctd>Higher\u003C\u002Ftd>\n\u003Ctd>Per IP\u002Fmonth\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Mobile\u003C\u002Ftd>\n\u003Ctd>Social media, app testing\u003C\u002Ftd>\n\u003Ctd>Medium\u003C\u002Ftd>\n\u003Ctd>Lowest\u003C\u002Ftd>\n\u003Ctd>Per GB\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\u003Ch3>Switching Proxy Types in Code\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import requests\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\n# Residential proxy (default)\nproxy = client.connection_url(country=\"us\")\nresponse = requests.get(\n    \"https:\u002F\u002Fexample.com\",\n    proxies={\"http\": proxy, \"https\": proxy},\n    timeout=30\n)\n# Datacenter proxy: not available at ProxyHat yet (coming soon)\n# Mobile proxy: add the -type-mobile flag to the username\nmobile = \"http:\u002F\u002FUSERNAME-country-us-type-mobile:PASSWORD@gate.proxyhat.com:8080\"\nresponse = requests.get(\n    \"https:\u002F\u002Fexample.com\",\n    proxies={\"http\": mobile, \"https\": mobile},\n    timeout=30\n)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Rotating vs Sticky Sessions\u003C\u002Fh2>\n\u003Cp>Rotating proxies assign a new IP for every request, ideal for large-scale scraping where you need maximum anonymity. Sticky sessions keep the same IP for a set duration, essential for multi-step workflows like login sequences or paginated navigation.\u003C\u002Fp>\n\u003Ch3>Rotating Proxies (New IP Each Request)\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import requests\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\n# Rotating residential URL (no sticky flag)\nproxy = client.connection_url(country=\"us\")\nproxies = {\"http\": proxy, \"https\": proxy}\nurls = [\n    \"https:\u002F\u002Fhttpbin.org\u002Fip\",\n    \"https:\u002F\u002Fhttpbin.org\u002Fip\",\n    \"https:\u002F\u002Fhttpbin.org\u002Fip\",\n]\nfor url in urls:\n    response = requests.get(url, proxies=proxies, timeout=30)\n    print(f\"IP: {response.json()['origin']}\")\n# Each request uses a different IP:\n# IP: 185.xxx.xxx.1\n# IP: 92.xxx.xxx.47\n# IP: 78.xxx.xxx.203\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Sticky Sessions (Same IP for Duration)\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import requests\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\n# Sticky session URL (keeps the same IP for up to 30 minutes)\nproxy = client.connection_url(country=\"us\", sticky=True)\nproxies = {\"http\": proxy, \"https\": proxy}\n# All requests through this URL use the same IP\nfor page in range(1, 4):\n    ip = requests.get(\"https:\u002F\u002Fhttpbin.org\u002Fip\", proxies=proxies, timeout=30).json()[\"origin\"]\n    response = requests.get(f\"https:\u002F\u002Fexample.com\u002Fproducts?page={page}\", proxies=proxies, timeout=30)\n    print(f\"Page {page}: IP {ip}\")\n# Same IP across all pages:\n# Page 1: IP 185.xxx.xxx.42\n# Page 2: IP 185.xxx.xxx.42\n# Page 3: IP 185.xxx.xxx.42\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Geo-Targeted Requests\u003C\u002Fh2>\n\u003Cp>Need data from a specific country? ProxyHat supports \u003Ca href=\"\u002Flocations\">geo-targeting across 195+ locations\u003C\u002Fa>. This is critical for localized SERP scraping, price monitoring, and content verification.\u003C\u002Fp>\n\u003Cpre>\u003Ccode>import requests\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\n# Target a specific country\nproxy = client.connection_url(country=\"us\")\nresponse = requests.get(\n    \"https:\u002F\u002Fwww.google.com\u002Fsearch?q=best+restaurants\",\n    proxies={\"http\": proxy, \"https\": proxy},\n    timeout=30\n)\n# Target a specific city (city targeting needs the region code too)\nproxy = client.connection_url(country=\"us\", region=\"new_york\", city=\"new_york_city\")\nresponse = requests.get(\n    \"https:\u002F\u002Fwww.google.com\u002Fsearch?q=best+restaurants\",\n    proxies={\"http\": proxy, \"https\": proxy},\n    timeout=30\n)\n# Using raw proxy URL with geo-targeting\n# Format: username-country-US:password@gate.proxyhat.com:8080\nproxies = {\n    \"http\": \"http:\u002F\u002Fuser-country-DE:pass@gate.proxyhat.com:8080\",\n    \"https\": \"http:\u002F\u002Fuser-country-DE:pass@gate.proxyhat.com:8080\",\n}\nresponse = requests.get(\"https:\u002F\u002Fwww.google.de\", proxies=proxies, timeout=30)\nprint(f\"Accessed from Germany: {response.status_code}\")\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Error Handling and Retries\u003C\u002Fh2>\n\u003Cp>Network requests fail. Proxies timeout. Targets block you. Robust error handling separates production scrapers from toy scripts.\u003C\u002Fp>\n\u003Ch3>Basic Retry Logic\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import time\nimport requests\nfrom requests.exceptions import ProxyError, Timeout, ConnectionError\ndef fetch_with_retry(url, proxies, max_retries=3, timeout=30):\n    \"\"\"Fetch a URL with automatic retry on failure.\"\"\"\n    for attempt in range(max_retries):\n        try:\n            response = requests.get(\n                url,\n                proxies=proxies,\n                timeout=timeout,\n                headers={\"User-Agent\": \"Mozilla\u002F5.0\"}\n            )\n            response.raise_for_status()\n            return response\n        except (ProxyError, Timeout, ConnectionError) as e:\n            wait = 2 ** attempt  # Exponential backoff\n            print(f\"Attempt {attempt + 1} failed: {e}. Retrying in {wait}s...\")\n            time.sleep(wait)\n        except requests.exceptions.HTTPError as e:\n            if e.response.status_code == 429:\n                wait = 10 * (attempt + 1)\n                print(f\"Rate limited. Waiting {wait}s...\")\n                time.sleep(wait)\n            elif e.response.status_code >= 500:\n                time.sleep(2 ** attempt)\n            else:\n                raise\n    raise Exception(f\"Failed to fetch {url} after {max_retries} attempts\")\n# Usage\nproxies = {\n    \"http\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n    \"https\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n}\nresponse = fetch_with_retry(\"https:\u002F\u002Fexample.com\u002Fdata\", proxies)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Automatic Retries with requests and urllib3\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import requests\nfrom requests.adapters import HTTPAdapter\nfrom urllib3.util.retry import Retry\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\nproxy = client.connection_url(country=\"us\")\n# The SDK builds the proxy URL; retries come from requests\u002Furllib3\nsession = requests.Session()\nsession.mount(\"https:\u002F\u002F\", HTTPAdapter(max_retries=Retry(\n    total=3,\n    backoff_factor=1,\n    status_forcelist=[429, 500, 502, 503]\n)))\nsession.proxies = {\"http\": proxy, \"https\": proxy}\nresponse = session.get(\"https:\u002F\u002Fexample.com\u002Fdata\", timeout=30)\nprint(response.status_code)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Concurrent Scraping with Threading\u003C\u002Fh2>\n\u003Cp>Sequential requests are slow. For production workloads, use Python's \u003Ccode>concurrent.futures\u003C\u002Fcode> to parallelize requests through proxies.\u003C\u002Fp>\n\u003Cpre>\u003Ccode>from concurrent.futures import ThreadPoolExecutor, as_completed\nimport requests\nfrom proxyhat import ProxyHat\nclient = ProxyHat(api_key=\"your_api_key_here\")\nproxy = client.connection_url(country=\"us\")  # rotating residential\nurls = [\n    \"https:\u002F\u002Fexample.com\u002Fproduct\u002F1\",\n    \"https:\u002F\u002Fexample.com\u002Fproduct\u002F2\",\n    \"https:\u002F\u002Fexample.com\u002Fproduct\u002F3\",\n    \"https:\u002F\u002Fexample.com\u002Fproduct\u002F4\",\n    \"https:\u002F\u002Fexample.com\u002Fproduct\u002F5\",\n]\ndef scrape(url):\n    \"\"\"Scrape a single URL through the proxy.\"\"\"\n    response = requests.get(url, proxies={\"http\": proxy, \"https\": proxy}, timeout=30)\n    return {\"url\": url, \"status\": response.status_code, \"length\": len(response.text)}\n# Run 5 concurrent requests\nresults = []\nwith ThreadPoolExecutor(max_workers=5) as executor:\n    futures = {executor.submit(scrape, url): url for url in urls}\n    for future in as_completed(futures):\n        try:\n            result = future.result()\n            results.append(result)\n            print(f\"OK: {result['url']} ({result['length']} bytes)\")\n        except Exception as e:\n            print(f\"Error: {futures[future]} - {e}\")\nprint(f\"\\nCompleted: {len(results)}\u002F{len(urls)}\")\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Async Scraping with asyncio and httpx\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import asyncio\nimport httpx\nasync def scrape_urls(urls, proxy_url, max_concurrent=10):\n    \"\"\"Scrape multiple URLs concurrently using async proxies.\"\"\"\n    semaphore = asyncio.Semaphore(max_concurrent)\n    async def fetch(client, url):\n        async with semaphore:\n            response = await client.get(url, timeout=30)\n            return {\"url\": url, \"status\": response.status_code}\n    async with httpx.AsyncClient(proxy=proxy_url) as client:\n        tasks = [fetch(client, url) for url in urls]\n        return await asyncio.gather(*tasks, return_exceptions=True)\n# Usage\nproxy_url = \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\"\nurls = [f\"https:\u002F\u002Fexample.com\u002Fpage\u002F{i}\" for i in range(1, 51)]\nresults = asyncio.run(scrape_urls(urls, proxy_url))\nsuccessful = [r for r in results if not isinstance(r, Exception)]\nprint(f\"Scraped {len(successful)}\u002F{len(urls)} pages\")\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Integration with Popular Python Libraries\u003C\u002Fh2>\n\u003Ch3>Using with Requests (Session)\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import requests\nsession = requests.Session()\nsession.proxies = {\n    \"http\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n    \"https\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n}\nsession.headers.update({\n    \"User-Agent\": \"Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64)\"\n})\n# All requests in this session use the proxy\nresponse = session.get(\"https:\u002F\u002Fexample.com\u002Fapi\u002Fproducts\")\nprint(response.json())\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Using with httpx\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import httpx\nproxy_url = \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\"\n# Synchronous\nwith httpx.Client(proxy=proxy_url) as client:\n    response = client.get(\"https:\u002F\u002Fhttpbin.org\u002Fip\")\n    print(response.json())\n# Asynchronous\nasync with httpx.AsyncClient(proxy=proxy_url) as client:\n    response = await client.get(\"https:\u002F\u002Fhttpbin.org\u002Fip\")\n    print(response.json())\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Using with aiohttp\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import aiohttp\nimport asyncio\nasync def fetch_with_aiohttp():\n    proxy_url = \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\"\n    async with aiohttp.ClientSession() as session:\n        async with session.get(\n            \"https:\u002F\u002Fhttpbin.org\u002Fip\",\n            proxy=proxy_url,\n            timeout=aiohttp.ClientTimeout(total=30)\n        ) as response:\n            data = await response.json()\n            print(f\"IP: {data['origin']}\")\nasyncio.run(fetch_with_aiohttp())\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Using with Scrapy\u003C\u002Fh3>\n\u003Cp>Add ProxyHat to your Scrapy spider by configuring the \u003Ccode>settings.py\u003C\u002Fcode>:\u003C\u002Fp>\n\u003Cpre>\u003Ccode># settings.py\nDOWNLOADER_MIDDLEWARES = {\n    \"scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware\": 110,\n}\nHTTP_PROXY = \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\"\n# Or set per-request in your spider:\nimport scrapy\nclass ProductSpider(scrapy.Spider):\n    name = \"products\"\n    start_urls = [\"https:\u002F\u002Fexample.com\u002Fproducts\"]\n    def start_requests(self):\n        for url in self.start_urls:\n            yield scrapy.Request(\n                url,\n                meta={\"proxy\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\"},\n                callback=self.parse\n            )\n    def parse(self, response):\n        for product in response.css(\".product-card\"):\n            yield {\n                \"name\": product.css(\"h2::text\").get(),\n                \"price\": product.css(\".price::text\").get(),\n            }\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Production Tips\u003C\u002Fh2>\n\u003Ch3>Connection Pooling and Timeouts\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import requests\nfrom requests.adapters import HTTPAdapter\nfrom urllib3.util.retry import Retry\nsession = requests.Session()\n# Configure retry strategy\nretry_strategy = Retry(\n    total=3,\n    backoff_factor=1,\n    status_forcelist=[429, 500, 502, 503, 504],\n)\nadapter = HTTPAdapter(\n    max_retries=retry_strategy,\n    pool_connections=10,\n    pool_maxsize=20\n)\nsession.mount(\"http:\u002F\u002F\", adapter)\nsession.mount(\"https:\u002F\u002F\", adapter)\nsession.proxies = {\n    \"http\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n    \"https\": \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\",\n}\n# Robust, production-ready request\nresponse = session.get(\"https:\u002F\u002Fexample.com\u002Fdata\", timeout=(5, 30))\nprint(response.status_code)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Logging and Monitoring\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>import logging\nimport time\nlogging.basicConfig(level=logging.INFO, format=\"%(asctime)s %(message)s\")\nlogger = logging.getLogger(\"scraper\")\ndef monitored_request(session, url):\n    \"\"\"Log request timing and status for monitoring.\"\"\"\n    start = time.time()\n    try:\n        response = session.get(url, timeout=30)\n        elapsed = time.time() - start\n        logger.info(f\"OK {response.status_code} {url} ({elapsed:.2f}s)\")\n        return response\n    except Exception as e:\n        elapsed = time.time() - start\n        logger.error(f\"FAIL {url} ({elapsed:.2f}s): {e}\")\n        raise\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>Environment Variables for Credentials\u003C\u002Fh3>\n\u003Cp>Never hardcode credentials. Use environment variables:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>import os\nfrom proxyhat import ProxyHat\nclient = ProxyHat(\n    api_key=os.environ[\"PROXYHAT_API_KEY\"]\n)\n# Or with raw proxy URL\nproxy_url = os.environ.get(\n    \"PROXY_URL\",\n    \"http:\u002F\u002Fuser:pass@gate.proxyhat.com:8080\"\n)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>For a full list of available proxy plans and traffic options, visit our \u003Ca href=\"\u002Fpricing\">pricing page\u003C\u002Fa>. For advanced use cases and endpoint reference, see the \u003Ca href=\"https:\u002F\u002Fdocs.proxyhat.com\u002F\" rel=\"noopener noreferrer\">API documentation\u003C\u002Fa>. You can also explore our guide on the \u003Ca href=\"\u002Fblog\u002Fbest-proxies-for-web-scraping-2026\">best proxies for web scraping in 2026\u003C\u002Fa> for provider comparisons.\u003C\u002Fp>\n\u003Cblockquote>\n\u003Ch3>Key Takeaways\u003C\u002Fh3>\n\u003Cul>\n\u003Cli>Install in one command: \u003Ccode>pip install proxyhat requests\u003C\u002Fcode> gets you started immediately.\u003C\u002Fli>\n\u003Cli>Use the SDK for simplicity: The ProxyHat Python SDK builds authenticated rotating or sticky proxy URLs from your API key.\u003C\u002Fli>\n\u003Cli>Choose the right proxy type: Residential for scraping, datacenter for speed, mobile for social platforms.\u003C\u002Fli>\n\u003Cli>Rotate vs stick: Use rotating proxies for bulk scraping, sticky sessions for multi-step workflows.\u003C\u002Fli>\n\u003Cli>Geo-target when needed: Specify country and city for localized data collection.\u003C\u002Fli>\n\u003Cli>Handle errors properly: Implement exponential backoff and retry logic for production reliability.\u003C\u002Fli>\n\u003Cli>Scale with concurrency: Use \u003Ccode>ThreadPoolExecutor\u003C\u002Fcode> or \u003Ccode>asyncio\u003C\u002Fcode> to parallelize requests.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Never hardcode credentials:\u003C\u002Fstrong> Store API keys in environment variables.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003C\u002Fblockquote>","Using Proxies in Python: Requests + SDK Guide","Learn how to configure proxies in Python with Requests and the ProxyHat SDK. Code examples for rotation, geo-targeting, retries, and async scraping.","\u002Fblog\u002Fusing-proxies-in-python",null,"Using Proxies in Python: Requests + SDK Guide | ProxyHat","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fusing-proxies-in-python-og.webp",[18,21,24,27,30],{"answer":19,"question":20},"Pass a proxies dictionary to any requests method: requests.get(url, proxies={\"http\": \"http:\u002F\u002Fuser:pass@host:port\", \"https\": \"http:\u002F\u002Fuser:pass@host:port\"}). The ProxyHat SDK simplifies this further by handling proxy configuration internally.","How do I set up a proxy in Python Requests?",{"answer":22,"question":23},"Rotating proxies assign a new IP address for every request, which is ideal for large-scale scraping. Sticky proxies maintain the same IP for a set duration (e.g., 10-30 minutes), which is necessary for login sessions, shopping carts, or paginated browsing where IP consistency matters.","What is the difference between rotating and sticky proxies in Python?",{"answer":25,"question":26},"Yes. ProxyHat proxies work with any HTTP client that supports proxy configuration, including aiohttp, httpx (async mode), and asyncio-based frameworks. Pass the proxy URL as the proxy parameter in your async client.","Can I use ProxyHat proxies with asyncio and aiohttp?",{"answer":28,"question":29},"Wrap your requests in try\u002Fexcept blocks catching ProxyError, Timeout, and ConnectionError. Implement exponential backoff (doubling wait time between retries) and set a maximum retry count. The ProxyHat SDK only builds the proxy URL, so configure retries in your HTTP client (for example urllib3 Retry with requests).","How do I handle proxy errors and timeouts in Python?",{"answer":31,"question":32},"For simple tasks, requests with the ProxyHat SDK is the easiest option. For high-concurrency async scraping, use httpx or aiohttp. For complex crawling with link following and data extraction, Scrapy with proxy middleware is the most powerful choice. All work seamlessly with ProxyHat proxies.","Which Python library is best for web scraping with proxies?",[34,35,36,37,38],"Proxies in Python prevent IP bans and allow you to scale web scraping operations reliably.","The ProxyHat SDK and requests library simplify proxy integration, authentication, and rotation.","Choose residential, datacenter, or mobile proxies based on your speed, cost, and detection needs.","Use rotating sessions for maximum anonymity or sticky sessions for multi-step workflows.","Implement error handling, retries, and concurrent scraping to ensure production reliability.",false,"2026-01-05T10:53:19+00:00","2026-07-19T03:13:07+00:00","2026-11-17T10:40:54+00:00","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fusing-proxies-in-python-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fusing-proxies-in-python-card.webp",12,{"name":47,"slug":48,"bio":49,"avatar_url":14,"website_url":14,"social_links":14},"ProxyHat Team","proxyhat-team","The ProxyHat editorial team covers proxies, web scraping, and data extraction.",[51],{"id":52,"slug":53,"name":54,"description":14,"meta_title":55,"meta_description":56,"parent_id":14},4,"developer-guides","Developer Guides","Developer Guides | ProxyHat Blog","Code tutorials and SDK guides for integrating proxies into your applications.",[58,62,66],{"id":59,"slug":60,"name":61},1,"web-scraping","Web Scraping",{"id":63,"slug":64,"name":65},9,"python","Python",{"id":45,"slug":67,"name":68},"sdk","SDK",{"en":13,"x-default":13},{"ko":71,"fr":72,"tr":73,"es":74,"de":75,"it":76,"pl":77,"en":13,"ru":78,"ja":79,"zh":80,"pt":81},"\u002Fko\u002Fblog\u002Fpython-proxy-sayongbeop","\u002Ffr\u002Fblog\u002Futiliser-des-proxies-en-python","\u002Ftr\u002Fblog\u002Fpython-ile-proxy-kullanimi","\u002Fes\u002Fblog\u002Fusar-proxies-en-python","\u002Fde\u002Fblog\u002Fproxies-in-python-verwenden","\u002Fit\u002Fblog\u002Futilizzando-proxies-in-python-richiesta-proxyhat-sdk","\u002Fpl\u002Fblog\u002Fkorzystanie-z-proxies-w-python-requests-proxyhat-sdk","\u002Fru\u002Fblog\u002Fispolzovanie-proksi-v-python","\u002Fja\u002Fblog\u002Fpython-de-prokishi-wo-tsukau","\u002Fcn\u002Fblog\u002Fpython-shiyong-daili","\u002Fpt\u002Fblog\u002Fusando-proxies-em-python",65,[84,111,137,154],{"id":85,"slug":86,"title":87,"excerpt":88,"featured_image_url":89,"featured_image_alt":87,"card_image_url":90,"og_image_url":91,"published_at":92,"updated_at":93,"content_updated_at":94,"reading_time_minutes":95,"is_featured":39,"indexable":4,"views":96,"author":97,"categories":98,"tags":100},210,"proxy-setup-for-ai-agents","Proxy Setup for AI Agents: browser-use, Crawl4AI and an MCP Server","Agents on cloud VMs exit from datacenter IPs. Here is current, working proxy configuration for browser-use, Crawl4AI and an MCP server, with a sticky-vs-rotating decision table and the cost traps to avoid.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fproxy-setup-for-ai-agents-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fproxy-setup-for-ai-agents-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fproxy-setup-for-ai-agents-og.webp","2026-10-24T09:00:00+00:00","2026-10-24T09:00:20+00:00","2026-10-03T09:31:26+00:00",14,31,{"name":47,"slug":48,"bio":49,"avatar_url":14,"website_url":14,"social_links":14},[99],{"id":52,"slug":53,"name":54,"description":14,"meta_title":55,"meta_description":56,"parent_id":14},[101,102,106,107],{"id":59,"slug":60,"name":61},{"id":103,"slug":104,"name":105},2,"residential-proxies","Residential Proxies",{"id":63,"slug":64,"name":65},{"id":108,"slug":109,"name":110},22,"playwright","Playwright",{"id":112,"slug":113,"title":114,"excerpt":115,"featured_image_url":116,"featured_image_alt":114,"card_image_url":117,"og_image_url":118,"published_at":119,"updated_at":120,"content_updated_at":94,"reading_time_minutes":95,"is_featured":39,"indexable":4,"views":121,"author":122,"categories":123,"tags":125},206,"camoufox-residential-proxies-python-guide","Camoufox with Residential Proxies: A Code-First Python Guide","How to run Camoufox, the C++-patched Firefox, behind residential proxies: current Python API, why geoip needs a sticky session, a fingerprint coherence checklist, and when Patchright or nodriver fits better.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fcamoufox-residential-proxies-python-guide-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fcamoufox-residential-proxies-python-guide-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fen\u002Fcamoufox-residential-proxies-python-guide-og.webp","2026-10-13T09:00:00+00:00","2026-10-13T09:00:22+00:00",45,{"name":47,"slug":48,"bio":49,"avatar_url":14,"website_url":14,"social_links":14},[124],{"id":52,"slug":53,"name":54,"description":14,"meta_title":55,"meta_description":56,"parent_id":14},[126,127,131,135,136],{"id":59,"slug":60,"name":61},{"id":128,"slug":129,"name":130},6,"anti-detection","Anti-Detection",{"id":132,"slug":133,"name":134},21,"headless-browser","Headless Browser",{"id":63,"slug":64,"name":65},{"id":103,"slug":104,"name":105},{"id":138,"slug":139,"title":140,"excerpt":141,"featured_image_url":142,"featured_image_alt":14,"card_image_url":143,"og_image_url":144,"published_at":145,"updated_at":41,"content_updated_at":146,"reading_time_minutes":45,"is_featured":39,"indexable":39,"views":147,"author":148,"categories":149,"tags":151},50,"reliable-scraping-architecture","Designing a Reliable Scraping Architecture","Design an end-to-end scraping system: scheduler, URL queue, crawler pool, proxy layer, parser, storage, and monitoring. Production-ready Python code with architecture diagrams.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Freliable-scraping-architecture-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Freliable-scraping-architecture-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Freliable-scraping-architecture-og.webp","2026-02-24T06:55:16+00:00","2026-10-03T08:21:20+00:00",68,{"name":47,"slug":48,"bio":49,"avatar_url":14,"website_url":14,"social_links":14},[150],{"id":52,"slug":53,"name":54,"description":14,"meta_title":55,"meta_description":56,"parent_id":14},[152,153],{"id":45,"slug":67,"name":68},{"id":59,"slug":60,"name":61},{"id":155,"slug":156,"title":157,"excerpt":158,"featured_image_url":159,"featured_image_alt":14,"card_image_url":160,"og_image_url":161,"published_at":162,"updated_at":41,"content_updated_at":163,"reading_time_minutes":164,"is_featured":39,"indexable":39,"views":165,"author":166,"categories":167,"tags":169},41,"monitoring-proxy-performance","Monitoring Proxy Performance: Latency, Success Rate, and Alerts","Learn how to instrument, monitor, and alert on proxy performance — track latency percentiles, success rates, error patterns, and bandwidth. Code examples in Python, Node.js, and Go.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fmonitoring-proxy-performance-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fmonitoring-proxy-performance-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fmonitoring-proxy-performance-og.webp","2026-02-15T00:39:23+00:00","2026-10-03T08:21:37+00:00",11,75,{"name":47,"slug":48,"bio":49,"avatar_url":14,"website_url":14,"social_links":14},[168],{"id":52,"slug":53,"name":54,"description":14,"meta_title":55,"meta_description":56,"parent_id":14},[170,171],{"id":45,"slug":67,"name":68},{"id":59,"slug":60,"name":61},[]]