10% off ALL new Proxies – CODE: 10pro

Python Requests Proxy: Mobile Proxy + Playwright Setup

Python Requests Proxy: Mobile Proxy + Playwright Setup

Direct Answer

To use a mobile proxy in Python, pass your proxy URL to the library you already use. With requests, set a proxies dict for HTTP or SOCKS5. With Playwright, pass a proxy object to launch(). Both route your traffic through a real German mobile IP — add your endpoint, username and password from your account.


Before You Start

You will need four values from your GermanProxy.io account:

  • Host and port of your endpoint
  • Username and password

The examples below use PROXY_HOST, PORT, USER and PASS as placeholders — replace them with your own. GermanProxy.io supports HTTP, SOCKS5 and OpenVPN, so you can pick whichever your tool prefers.


Using a Mobile Proxy with requests (HTTP)

The requests library reads a proxies dictionary. Point both http and https at your endpoint:

import requests

proxies = {
    "http":  "http://USER:PASS@PROXY_HOST:PORT",
    "https": "http://USER:PASS@PROXY_HOST:PORT",
}

resp = requests.get("https://www.example.de", proxies=proxies, timeout=30)
print(resp.status_code)
print(resp.text[:200])

To confirm the IP your target sees, request an IP-echo endpoint through the same proxy before you build the rest of your pipeline.


Using a Mobile Proxy with requests (SOCKS5)

For SOCKS5, install the optional dependency first:

pip install "requests[socks]"

Then swap the scheme to socks5:

import requests

proxies = {
    "http":  "socks5://USER:PASS@PROXY_HOST:PORT",
    "https": "socks5://USER:PASS@PROXY_HOST:PORT",
}

resp = requests.get("https://www.example.de", proxies=proxies, timeout=30)
print(resp.status_code)

Use socks5h:// instead of socks5:// if you want DNS resolution to happen at the proxy rather than locally.


Using a Mobile Proxy with Playwright

Playwright takes a proxy object when you launch the browser:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server":   "http://PROXY_HOST:PORT",
            "username": "USER",
            "password": "PASS",
        }
    )
    page = browser.new_page()
    page.goto("https://www.example.de", wait_until="domcontentloaded")
    print(page.title())
    browser.close()

The same proxy argument works for firefox and webkit. For device-level consistency — so browser features like WebRTC also use the mobile endpoint — consider routing the whole machine over OpenVPN instead; see what a WebRTC leak is.


Sticky Sessions vs. Rotation

  • Sticky session: hold the same German mobile IP for the length of a task — ideal for multi-step flows that should look like one continuous user.
  • Rotation on demand: request a fresh IP when you want one — useful for spreading independent requests.

Choose per workflow rather than rotating blindly. For the concepts, see sticky sessions and IP rotation explained.


Scrape Responsibly

A mobile proxy improves reliability for legitimate data collection — it is not a tool to circumvent access controls or platform rules. Keep your pipeline clean and defensible:

  1. Respect robots.txt and each site's terms of service.
  2. Send requests at a human-reasonable rate — add delays and avoid hammering servers.
  3. Collect only what you need, and handle any personal data in line with the GDPR.
  4. Set an honest User-Agent that identifies your client, not a misleading one.

These habits keep both your data and your IP reputation healthy.


FAQ

Does this work with Scrapy, httpx or Selenium too?

Yes, but the wiring differs a little per library. Scrapy takes the endpoint via the proxy request meta key or a downloader middleware. httpx uses the proxy= argument on its Client/AsyncClient (the old proxies= argument was removed in httpx 0.28.0 — passing it now raises a TypeError; use mounts= if you need different routes per scheme). Selenium is the exception: Chromium's --proxy-server flag does not accept user:pass credentials, so for an authenticated endpoint like ours you have to answer the auth challenge yourself — via the Chrome DevTools Protocol (Fetch.continueWithAuth) or a small credentials extension, or by using SeleniumBase's Driver(proxy="user:pass@host:port"). The host, port and credentials are the same across all of them — only the auth handling changes.

Why do I get connection errors?

Check the host, port and credentials first, confirm the scheme (http vs socks5), and raise your timeout — mobile latency is higher than datacenter. Verify the proxy with a simple IP-echo request before debugging your scraper.

HTTP or SOCKS5 — which should I use?

HTTP is simplest for web requests; SOCKS5 is more flexible for non-HTTP traffic and lets the proxy handle DNS (socks5h). For most Python scraping, either works — see SOCKS5 vs HTTP proxy.


CTA

Build your pipeline on real German mobile IPs. Get a German mobile proxy — HTTP/SOCKS5/OpenVPN, sticky sessions, fair-use 20 GB/day.


Get a German mobile proxy: Real 4G/5G IPs from Germany, fair-use 20 GB/day — compare German mobile proxy plans or start small with a shared 5G proxy.

Telegram Support
Nach oben scrollen