[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-python-urllib-request-en":3},{"post":4,"faq":33,"faqLdJson":56,"faqLdJsonScript":84,"alternatePaths":85,"recommendations":87,"contentLocale":20},{"authors":5,"custom_excerpt":13,"excerpt":13,"feature_image":14,"featured":15,"id":16,"meta_description":13,"meta_title":17,"og_description":8,"og_image":8,"og_title":8,"primary_author":18,"primary_tag":19,"published_at":22,"reading_time":23,"slug":24,"status":25,"tags":26,"title":17,"twitter_description":8,"twitter_image":8,"twitter_title":31,"updated_at":22,"visibility":21,"lexical":32},[6],{"bio":7,"facebook":8,"instagram":8,"linkedin":8,"location":9,"name":10,"profile_image":11,"slug":12,"tiktok":8,"twitter":8,"website":8,"youtube":8},"As a Senior Editor at Rola IP, Daniel is a true tech enthusiast. In his spare time, he enjoys tinkering with Python scripts, engaging in open-source communities, and exploring core network mechanisms.",null,"Daniel 现任 Rola IP 高级编辑，是一位名副其实的技术爱好者。工作之余，他热衷于钻研 Python 脚本、活跃于开源社区，并不断探索核心网络底层的运行机制。","Daniel Zhao","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F08\u002FPixPin_2026-08-13_10-47-55.png","daniel","Route urllib.request through a proxy, add authentication, rotate the exit IP per request, and stop urllib silently using a proxy you did not set.","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002FPython-urllib.request-proxy-setup-article-cover-image.webp",false,"6aa7b7e44956c90001bef919","Python urllib.request Proxy Setup: Authentication, Rotation, and Troubleshooting",{"bio":7,"facebook":8,"instagram":8,"linkedin":8,"location":9,"name":10,"profile_image":11,"slug":12,"tiktok":8,"twitter":8,"website":8,"youtube":8},{"description":8,"feature_image":8,"name":20,"slug":20,"visibility":21},"en","public","2026-09-14T09:40:25.000Z",9,"python-urllib-request","published",[27,28],{"description":8,"feature_image":8,"name":20,"slug":20,"visibility":21},{"description":8,"feature_image":8,"name":29,"slug":30,"visibility":21},"教程","guides","python urllib request","{\"root\":{\"children\":[{\"type\":\"markdown\",\"version\":1,\"markdown\":\"Build a `ProxyHandler`, wrap it in an opener, and either install that opener globally or call it directly. Four lines get a request out through a proxy. The part that costs people an afternoon is different: `urllib.request` already installs a proxy handler of its own from environment variables and operating system settings, so a script with no proxy code can still be going through one, and a script with proxy code can be fighting a setting it never sees.\\n\\n\\n## The short version\\n\\n```python\\nfrom urllib.request import ProxyHandler, build_opener\\n\\nproxy = ProxyHandler({\\n    \\\"http\\\":  \\\"http:\u002F\u002FUSERNAME:PASSWORD@HOST:PORT\\\",\\n    \\\"https\\\": \\\"http:\u002F\u002FUSERNAME:PASSWORD@HOST:PORT\\\",\\n})\\nopener = build_opener(proxy)\\nprint(opener.open(\\\"http:\u002F\u002Fip123.in\u002Fip.json\\\").read().decode())\\n```\\n\\nAt the time of review, this example endpoint returned HTTP 200 and JSON containing `ip` and `country`. Treat it as a demonstration endpoint; use an endpoint you control or are authorized to query in production.\\n\\n`build_opener` returns an opener that uses your handler. Calling `opener.open()` keeps the proxy scoped to that opener. If you would rather every later `urlopen()` call in the process use it, add `install_opener(opener)` once and carry on using `urlopen` normally.\\n\\nNote that both the `http` and `https` keys hold an `http:\u002F\u002F` URL. That surprises people, but the key names the scheme of the destination, not the scheme of the proxy hop.\\n\\n## Why urllib may already be using a proxy you did not set\\n\\nThis is the behaviour worth knowing before you debug anything else.\\n\\nThe Python documentation states that `ProxyHandler`'s default \\\"is to read the list of proxies from the environment variables `\u003Cprotocol>_proxy`\\\", and that if no such variables are set, \\\"in a Windows environment proxy settings are obtained from the registry's Internet Settings section, and in a macOS environment proxy information is retrieved from the System Configuration Framework\\\". \\n\\nThe `urlopen` entry is blunter: \\\"if proxy settings are detected (for example, when a `*_proxy` environment variable like `http_proxy` is set), `ProxyHandler` is default installed and makes sure the requests are handled through the proxy\\\" (\u003Ca href=\\\"https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Furllib.request.html\\\" rel=\\\"nofollow\\\">urllib.request documentation\u003C\u002Fa>).\\n\\nSo a plain `urlopen(\\\"https:\u002F\u002Fexample.com\\\")` on a Windows machine whose Internet Settings name a corporate proxy goes through that proxy. Nothing in your code says so.\\n\\n![urllib-proxy-resolution-order](https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002Furllib-proxy-resolution-order.png)\\n\\n*Figure 1. Illustrative diagram of the resolution order described in the Python 3 `urllib.request` documentation.*\\n\\nThree details from the same documentation decide most confusing cases:\\n\\n- **Lowercase wins.** `getproxies()` \\\"scans the environment for variables named `\u003Cscheme>_proxy`, in a case insensitive approach\\\", and \\\"if both lowercase and uppercase environment variables exist (and disagree), lowercase is preferred.\\\"\\n- **Empty dictionary means direct.** \\\"To disable autodetected proxy pass an empty dictionary.\\\" `ProxyHandler({})` is how you guarantee a direct connection.\\n- **CGI is special.** \\\"`HTTP_PROXY` will be ignored if a variable `REQUEST_METHOD` is set.\\\" This guards against a CGI gateway turning an incoming `Proxy:` header into an environment variable.\\n\\nWhen a proxy behaves differently on your machine than on a colleague's, check `urllib.request.getproxies()` on both before touching the code.\\n\\n```python\\nfrom urllib.request import getproxies\\nprint(getproxies())   # {} means nothing was auto-detected\\n```\\n\\n## What getproxies() actually returns\\n\\nThe three rules above are easier to trust once you watch them run. The session below was run for this guide on Python 3.11.15 under Linux on 11 September 2026, using `env -i` so each command starts from an empty environment. The addresses are \u003Ca href=\\\"https:\u002F\u002Fwww.rfc-editor.org\u002Frfc\u002Frfc5737\\\" rel=\\\"nofollow\\\">RFC 5737\u003C\u002Fa> documentation ranges rather than working proxies.\\n\\nTo reproduce the key cases in a POSIX shell, save the following as `probe.py` and run each command from a clean environment. The printed dictionaries should match the table below (values may differ if you change the test addresses):\\n\\n```sh\\ncat > probe.py \u003C\u003C'PY'\\nfrom urllib.request import getproxies\\nprint(getproxies())\\nPY\\nenv -i PATH=\\\"$PATH\\\" python3 probe.py\\nenv -i PATH=\\\"$PATH\\\" HTTP_PROXY=http:\u002F\u002F203.0.113.99:3128 python3 probe.py\\nenv -i PATH=\\\"$PATH\\\" HTTP_PROXY=http:\u002F\u002F203.0.113.99:3128 REQUEST_METHOD=GET python3 probe.py\\nenv -i PATH=\\\"$PATH\\\" http_proxy=http:\u002F\u002F198.51.100.10:8080 REQUEST_METHOD=GET python3 probe.py\\nenv -i PATH=\\\"$PATH\\\" HTTP_PROXY=http:\u002F\u002F203.0.113.99:3128 http_proxy=http:\u002F\u002F198.51.100.10:8080 python3 probe.py\\nenv -i PATH=\\\"$PATH\\\" YARN_HTTPS_PROXY=http:\u002F\u002F203.0.113.99:3128 FOO_PROXY=http:\u002F\u002F198.51.100.10:8080 python3 probe.py\\n```\\n\\nOn Windows, set and clear the variables in a separate PowerShell process for each case, or run the same probe under WSL. Environment and Python-version differences can change the exact dictionary output.\\n\\n![urllib-getproxies-real-run](https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002Furllib-getproxies-real-run.png)\\n\\n*Figure 2. A recorded run of `getproxies()` on Python 3.11.15, Linux. Reproduce it with the `env -i` commands shown.*\\n\\n| Environment | `getproxies()` returned | What it shows |\\n|---|---|---|\\n| Nothing set | `{}` | The clean baseline |\\n| `HTTP_PROXY` only | `{'http': 'http:\u002F\u002F203.0.113.99:3128'}` | Uppercase alone is honoured |\\n| `HTTP_PROXY` plus `REQUEST_METHOD` | `{}` | The CGI rule drops the proxy entirely |\\n| `http_proxy` plus `REQUEST_METHOD` | `{'http': 'http:\u002F\u002F198.51.100.10:8080'}` | Lowercase is not affected by the CGI rule |\\n| Both cases, disagreeing | `{'http': 'http:\u002F\u002F198.51.100.10:8080'}` | Lowercase wins, as documented |\\n| `YARN_HTTPS_PROXY` and `FOO_PROXY` | `{'yarn_https': ..., 'foo': ...}` | Any variable ending in `_proxy` becomes an entry |\\n\\nTwo results are worth pausing on.\\n\\nThe CGI rule is narrower than it first reads. Setting `REQUEST_METHOD` removed the uppercase `HTTP_PROXY` entry completely, while the lowercase `http_proxy` in the fourth run survived it. If you are debugging a web-gateway deployment, which case the variable uses decides whether it takes effect.\\n\\nThe last run is the one that bites in real projects. `getproxies()` strips the `_proxy` suffix and treats whatever remains as a scheme name, so `YARN_HTTPS_PROXY` became a scheme called `yarn_https` and `FOO_PROXY` became one called `foo`. A build machine carrying npm, yarn, Docker or Electron proxy variables will show all of them in Python's proxy dictionary. They do not match the `http` or `https` keys urllib looks for when it routes a request, so they are noise rather than a redirect, but they make the output hard to read when you are trying to find the one entry that matters.\\n\\n## Proxy authentication in urllib.request\\n\\nMost paid proxies need a username and password. The credentials-in-the-URL form in the short version above works for basic authentication, and it is the form the standard library accepts. It is also the form that leaks: the URL ends up in tracebacks, logs and process listings.\\n\\nThe explicit route keeps the password out of the URL. `ProxyBasicAuthHandler` \\\"handles authentication with the proxy\\\" and takes a password manager, per the same documentation:\\n\\n```python\\nfrom urllib.request import (\\n    ProxyHandler, ProxyBasicAuthHandler,\\n    HTTPPasswordMgrWithDefaultRealm, build_opener,\\n)\\n\\nproxy_url = \\\"http:\u002F\u002FHOST:PORT\\\"\\n\\npwd_mgr = HTTPPasswordMgrWithDefaultRealm()\\npwd_mgr.add_password(None, proxy_url, \\\"USERNAME\\\", \\\"PASSWORD\\\")\\n\\nopener = build_opener(\\n    ProxyHandler({\\\"http\\\": proxy_url, \\\"https\\\": proxy_url}),\\n    ProxyBasicAuthHandler(pwd_mgr),\\n)\\nprint(opener.open(\\\"http:\u002F\u002Fip123.in\u002Fip.json\\\").read().decode())\\n```\\n\\n![urllib-proxy-auth-routes](https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002Furllib-proxy-auth-routes.png)\\n\\n*Figure 3. Illustrative comparison of the two routes. Both authenticate identically on the wire; they differ in where the password can end up.*\\n\\n`ProxyDigestAuthHandler` is the equivalent when the proxy asks for digest rather than basic. Read your provider's documentation rather than guessing, because sending digest credentials to a basic-auth endpoint fails with the same 407 as a wrong password.\\n\\nOne thing `urllib.request` does not document a handler for is SOCKS. Its documentation describes proxy handling for the schemes urllib itself speaks and lists no SOCKS handler, so a `socks5:\u002F\u002F` endpoint needs a third-party library or a different client. If your provider offers both, point urllib at the HTTP endpoint.\\n\\n## Rotating the exit IP per request\\n\\n`urllib.request` has no session or rotation concept. It opens a connection, makes a request, and forgets. Rotation therefore has to come from the proxy service, and it is configured in the credentials rather than in Python.\\n\\nRola IP's [Python proxy integration](https:\u002F\u002Fdoc.rola-ip.co\u002Fguide\u002Fintegration\u002Fpython.html) documentation publishes the account-name pattern `USERNAME-country-COUNTRYCODE-sid-SESSION`, where the session value is a number you choose. The same page publishes `gate.rola.vip:1000` for HTTP and `gate.rola.vip:2000` for SOCKS5, and its sample generates a new session value for each rotating request. Whether reusing a session holds one exit, and how quickly a new session changes it, depends on the provider's current session policy; verify that behavior in your dashboard before relying on it.\\n\\nBecause urllib builds an opener per proxy configuration, a new exit means a new opener:\\n\\n```python\\nimport time\\nfrom urllib.request import ProxyHandler, build_opener\\n\\nUSER, PASSWORD, COUNTRY = \\\"USERNAME\\\", \\\"PASSWORD\\\", \\\"us\\\"\\nGATEWAY = \\\"gate.rola.vip:1000\\\"\\n\\ndef fetch(url, session_id=None):\\n    \\\"\\\"\\\"One request. A new session_id means a new exit IP.\\\"\\\"\\\"\\n    sid = session_id or int(time.time() * 1_000_000)\\n    account = f\\\"{USER}-country-{COUNTRY}-sid-{sid}\\\"\\n    proxy = f\\\"http:\u002F\u002F{account}:{PASSWORD}@{GATEWAY}\\\"\\n    opener = build_opener(ProxyHandler({\\\"http\\\": proxy, \\\"https\\\": proxy}))\\n    with opener.open(url, timeout=30) as resp:\\n        return resp.read().decode()\\n\\nfor _ in range(3):\\n    print(fetch(\\\"http:\u002F\u002Fip123.in\u002Fip.json\\\"))   # three separate exits\\n\\nsid = 424242\\npage1 = fetch(\\\"http:\u002F\u002Fip123.in\u002Fip.json\\\", sid)  # reuse a sid to test provider persistence\\npage2 = fetch(\\\"http:\u002F\u002Fip123.in\u002Fip.json\\\", sid)  # verify the observed exit yourself\\n```\\n\\n![urllib-rotation-sid-to-exit](https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002Furllib-rotation-sid-to-exit.png)\\n\\n*Figure 4. Illustrative diagram of the session-to-exit mapping. The account-name pattern and gateway ports are published in Rola IP's Python integration documentation; session persistence and rotation timing remain provider-policy dependent.*\\n\\nConfirm the account-name syntax in your own dashboard before deploying. Providers change accepted parameters, and a suffix that no longer parses usually presents as an authentication failure rather than as a syntax error.\\n\\nThe [residential proxy](https:\u002F\u002Frola-ip.co\u002Fresidential-ip\u002F) product page lists the location and session controls available on the rotating network. Whether you need them depends on the job: a handful of requests against a tolerant endpoint does not, and a job that must look like separate visitors does.\\n\\nUse proxy rotation only for authorized testing and data collection. Follow the target site's terms of service, robots and access rules, privacy requirements, and applicable laws. A rotating proxy does not guarantee access, anonymity, or immunity from blocking.\\n\\n## Always set a timeout\\n\\n`urlopen` and `opener.open` accept a `timeout` argument. Leave it out and a proxy that accepts the connection and then stalls will hang the call for as long as the platform default allows, which on a long-running script is indistinguishable from a hang in your own code.\\n\\n```python\\nopener.open(url, timeout=30)\\n```\\n\\nSet it on every call that crosses a proxy.\\n\\n## Verify the exit before you trust it\\n\\nA request that returns 200 proves the proxy accepted you. It does not prove where the request came out.\\n\\n1. Record your own public address first, with the proxy switched off.\\n2. Run the request through the proxy against an endpoint that echoes the caller's IP.\\n3. Confirm the address differs from the one you recorded.\\n4. Confirm the country matches what you requested, rather than only that something changed.\\n5. Repeat with the same session value and then a different one, and confirm the exit holds and then changes.\\n\\nRola IP's [what is my IP](https:\u002F\u002Frola-ip.co\u002Ftools\u002Fwhat-is-my-ip\u002F) tool shows the address a page sees, which is a useful cross-check when a script and a browser disagree.\\n\\n```python\\nimport json\\nfrom urllib.request import ProxyHandler, build_opener\\n\\nproxy = \\\"http:\u002F\u002FUSERNAME:PASSWORD@HOST:PORT\\\"\\nopener = build_opener(ProxyHandler({\\\"http\\\": proxy, \\\"https\\\": proxy}))\\ndata = json.loads(opener.open(\\\"http:\u002F\u002Fip123.in\u002Fip.json\\\", timeout=30).read())\\nprint(data.get(\\\"ip\\\"), data.get(\\\"country\\\"))\\n```\\n\\n## When to stop using urllib\\n\\n`urllib.request` is in the standard library, which is its whole advantage. Everything below is something you would otherwise write yourself.\\n\\n| What you need | urllib.request | Practical alternative |\\n|---|---|---|\\n| One request through a proxy, no dependencies | Fine | None needed |\\n| Connection reuse across many requests | Not provided | `requests.Session` or `httpx` |\\n| Automatic retries with backoff | Not provided | `urllib3` retry policy, via `requests` |\\n| SOCKS5 endpoint | No handler documented | `requests` with SOCKS support, or another client |\\n| Credentials kept out of the URL | Handler plus password manager | One `proxies=` argument |\\n| Concurrent requests | Thread it yourself | `httpx` or `aiohttp` |\\n\\nIf your script is growing past a single fetch, our guide to the [Python requests proxy](https:\u002F\u002Frola-ip.co\u002Fblog\u002Fpython-requests-proxy\u002F) covers the session, retry and rotation patterns that urllib leaves to you. Staying on urllib is a reasonable choice when the dependency budget is zero and the job is small.\\n\\n## Fixing common urllib proxy errors\\n\\nChange one thing at a time. Altering the credentials, the scheme and the endpoint together tells you nothing when the next attempt works.\\n\\n| Symptom | Likely cause | What to check |\\n|---|---|---|\\n| `HTTP Error 407: Proxy Authentication Required` | Credentials missing, wrong, or the wrong auth scheme | Confirm the proxy password is not the dashboard login; try `ProxyBasicAuthHandler` explicitly |\\n| Request succeeds but the IP is unchanged | Your handler was never used | You called `urlopen` rather than `opener.open`, and never called `install_opener` |\\n| Proxy applies when your code sets none | Environment or OS settings were auto-detected | Print `getproxies()`; pass `ProxyHandler({})` to force direct |\\n| Works for you, not for a colleague | Different environment variables or OS proxy settings | Compare `getproxies()` output on both machines |\\n| `URLError` with a connection refused | Wrong port, or the gateway is not reachable from that network | Retest the same endpoint from a shell before blaming Python |\\n| Call hangs indefinitely | No timeout set | Add `timeout=` to every `open()` call |\\n| HTTPS requests fail, HTTP works | The `https` key is missing from the proxy dictionary | Set both keys, each to the proxy's own URL |\\n| Exit country is wrong | The account-name parameter was altered or dropped | Regenerate the account string in the dashboard at country level |\\n| Environment variable ignored under a web gateway | `REQUEST_METHOD` is set, so `HTTP_PROXY` is skipped | Configure the proxy explicitly rather than through the environment |\"},{\"children\":[],\"direction\":null,\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":null,\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}",{"items":34,"inline":15},[35,38,41,44,47,50,53],{"title":36,"desc":37},"How do I set a proxy for all urllib requests at once?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">Build the opener and pass it to \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>install_opener()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\">. Every subsequent \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>urlopen()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> in that process uses it. Skip \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>install_opener\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> when you want the proxy limited to one part of your code, and call \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>opener.open()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> instead.\u003C\u002Fspan>\u003C\u002Fp>",{"title":39,"desc":40},"Does urllib read http_proxy automatically?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">Yes. The documentation states that \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>ProxyHandler\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> reads \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>&lt;protocol&gt;_proxy\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> variables by default and that \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>urlopen\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> installs a \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>ProxyHandler\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> automatically once proxy settings are detected. Lowercase variables take precedence over uppercase when the two disagree.\u003C\u002Fspan>\u003C\u002Fp>",{"title":42,"desc":43},"How do I stop urllib from using any proxy?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">Pass an empty dictionary: \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>build_opener(ProxyHandler({}))\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\">. The documentation names this as the way to disable an autodetected proxy.\u003C\u002Fspan>\u003C\u002Fp>",{"title":45,"desc":46},"Does urllib support SOCKS5?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">The \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>urllib.request\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> documentation lists no SOCKS handler. Use the provider's HTTP endpoint with urllib, or switch to a client with SOCKS support for a \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>socks5:\u002F\u002F\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> endpoint.\u003C\u002Fspan>\u003C\u002Fp>",{"title":48,"desc":49},"Why is my proxy working in the terminal but not in Python?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">The terminal and the Python process may be reading different settings. A shell that exports \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>http_proxy\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> affects tools launched from it; a Python service started elsewhere sees its own environment. Print \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>getproxies()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> inside the running process rather than assuming it matches your shell.\u003C\u002Fspan>\u003C\u002Fp>",{"title":51,"desc":52},"Why does getproxies() show entries I never set?","\u003Cp dir=\"ltr\">\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>getproxies()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> treats any environment variable ending in \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>_proxy\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> as a proxy entry and uses whatever precedes the suffix as the scheme name. On a machine with npm, yarn, Docker or Electron proxy variables set, those appear in the dictionary as schemes such as \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>yarn_https\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\">. They do not match the \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>http\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> or \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>https\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> keys urllib routes on, so they are clutter rather than a redirect.\u003C\u002Fspan>\u003C\u002Fp>",{"title":54,"desc":55},"Can I rotate IPs with urllib?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">Not within urllib itself, because it has no session concept. Rotation comes from the proxy service, usually through a parameter in the account name, and in urllib you build a new opener for each configuration you want.\u003C\u002Fspan>\u003C\u002Fp>",{"@context":57,"@type":58,"@id":59,"mainEntity":60},"https:\u002F\u002Fschema.org","FAQPage","https:\u002F\u002Frola-ip.co\u002Fblog\u002Fpython-urllib-request\u002F#faq",[61,66,69,72,75,78,81],{"@type":62,"name":36,"acceptedAnswer":63},"Question",{"@type":64,"text":65},"Answer","Build the opener and pass it to install_opener(). Every subsequent urlopen() in that process uses it. Skip install_opener when you want the proxy limited to one part of your code, and call opener.open() instead.",{"@type":62,"name":39,"acceptedAnswer":67},{"@type":64,"text":68},"Yes. The documentation states that ProxyHandler reads &lt;protocol&gt;_proxy variables by default and that urlopen installs a ProxyHandler automatically once proxy settings are detected. Lowercase variables take precedence over uppercase when the two disagree.",{"@type":62,"name":42,"acceptedAnswer":70},{"@type":64,"text":71},"Pass an empty dictionary: build_opener(ProxyHandler({})). The documentation names this as the way to disable an autodetected proxy.",{"@type":62,"name":45,"acceptedAnswer":73},{"@type":64,"text":74},"The urllib.request documentation lists no SOCKS handler. Use the provider's HTTP endpoint with urllib, or switch to a client with SOCKS support for a socks5:\u002F\u002F endpoint.",{"@type":62,"name":48,"acceptedAnswer":76},{"@type":64,"text":77},"The terminal and the Python process may be reading different settings. A shell that exports http_proxy affects tools launched from it; a Python service started elsewhere sees its own environment. Print getproxies() inside the running process rather than assuming it matches your shell.",{"@type":62,"name":51,"acceptedAnswer":79},{"@type":64,"text":80},"getproxies() treats any environment variable ending in _proxy as a proxy entry and uses whatever precedes the suffix as the scheme name. On a machine with npm, yarn, Docker or Electron proxy variables set, those appear in the dictionary as schemes such as yarn_https. They do not match the http or https keys urllib routes on, so they are clutter rather than a redirect.",{"@type":62,"name":54,"acceptedAnswer":82},{"@type":64,"text":83},"Not within urllib itself, because it has no session concept. Rotation comes from the proxy service, usually through a parameter in the account name, and in urllib you build a new opener for each configuration you want.","{\"@context\":\"https:\u002F\u002Fschema.org\",\"@type\":\"FAQPage\",\"@id\":\"https:\u002F\u002Frola-ip.co\u002Fblog\u002Fpython-urllib-request\u002F#faq\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"How do I set a proxy for all urllib requests at once?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Build the opener and pass it to install_opener(). Every subsequent urlopen() in that process uses it. Skip install_opener when you want the proxy limited to one part of your code, and call opener.open() instead.\"}},{\"@type\":\"Question\",\"name\":\"Does urllib read http_proxy automatically?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. The documentation states that ProxyHandler reads &lt;protocol&gt;_proxy variables by default and that urlopen installs a ProxyHandler automatically once proxy settings are detected. Lowercase variables take precedence over uppercase when the two disagree.\"}},{\"@type\":\"Question\",\"name\":\"How do I stop urllib from using any proxy?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Pass an empty dictionary: build_opener(ProxyHandler({})). The documentation names this as the way to disable an autodetected proxy.\"}},{\"@type\":\"Question\",\"name\":\"Does urllib support SOCKS5?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The urllib.request documentation lists no SOCKS handler. Use the provider's HTTP endpoint with urllib, or switch to a client with SOCKS support for a socks5:\u002F\u002F endpoint.\"}},{\"@type\":\"Question\",\"name\":\"Why is my proxy working in the terminal but not in Python?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The terminal and the Python process may be reading different settings. A shell that exports http_proxy affects tools launched from it; a Python service started elsewhere sees its own environment. Print getproxies() inside the running process rather than assuming it matches your shell.\"}},{\"@type\":\"Question\",\"name\":\"Why does getproxies() show entries I never set?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"getproxies() treats any environment variable ending in _proxy as a proxy entry and uses whatever precedes the suffix as the scheme name. On a machine with npm, yarn, Docker or Electron proxy variables set, those appear in the dictionary as schemes such as yarn_https. They do not match the http or https keys urllib routes on, so they are clutter rather than a redirect.\"}},{\"@type\":\"Question\",\"name\":\"Can I rotate IPs with urllib?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Not within urllib itself, because it has no session concept. Rotation comes from the proxy service, usually through a parameter in the account name, and in urllib you build a new opener for each configuration you want.\"}}]}",[86],"\u002Fblog\u002Fpython-urllib-request\u002F",{"prev":88,"next":101,"related":112,"popular":146,"latest":212},{"id":89,"title":90,"slug":91,"feature_image":92,"published_at":93,"twitter_title":94,"primary_tag":95,"tags":96},"6aa7c4484956c90001bef961","407 Proxy Authentication Required: Diagnose and Fix It","407-proxy-authentication-required","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002F407-Proxy-Authentication-Required-article-cover-image.webp","2026-09-14T10:08:18.000Z","407 Proxy Authentication",{"name":20,"slug":20},[97,98],{"name":20,"slug":20,"visibility":21},{"name":99,"slug":100,"visibility":21},"排障指南","troubleshooting",{"id":102,"title":103,"slug":104,"feature_image":105,"published_at":106,"twitter_title":107,"primary_tag":108,"tags":109},"6aa7a01b4956c90001bef8e1","C# HttpClient With Proxy: Auth, Rotation, and Fixes","csharp-httpclient-with-proxy","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002FC--HttpClient-With-Proxy-Auth--Rotation--and-Fixes.webp","2026-09-14T08:07:59.000Z","c# httpclient with proxy",{"name":20,"slug":20},[110,111],{"name":20,"slug":20,"visibility":21},{"name":29,"slug":30,"visibility":21},[113,124,135],{"id":114,"title":115,"slug":116,"feature_image":117,"published_at":118,"twitter_title":119,"primary_tag":120,"tags":121},"6b0d3e4b92ab700001dc0a73","Scrape Indeed Jobs with Python: Extract Job Fields and Export to CSV","scrape-indeed-jobs","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FScrape-Indeed-Jobs.webp","2026-11-30T09:37:05.000Z","indeed job scraper",{"name":20,"slug":20},[122,123],{"name":20,"slug":20,"visibility":21},{"name":29,"slug":30,"visibility":21},{"id":125,"title":126,"slug":127,"feature_image":128,"published_at":129,"twitter_title":130,"primary_tag":131,"tags":132},"6b0d2bcb92ab700001dc0a12","Node.js HTTP Proxy Tutorial: Send HTTPS Requests with Rola IP and Verify the Exit IP","node-js-http-proxy","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FNode.js-HTTP-Proxy-Tutorial_-Send-HTTPS-Requests-with-Rola-IP-and-Verify-the-Exit-IP.webp","2026-11-30T07:58:57.000Z","node js http proxy",{"name":20,"slug":20},[133,134],{"name":20,"slug":20,"visibility":21},{"name":29,"slug":30,"visibility":21},{"id":136,"title":137,"slug":138,"feature_image":139,"published_at":140,"twitter_title":141,"primary_tag":142,"tags":143},"6b09485d92ab700001dc0953","How to Set Up Chrome DevTools MCP for Multi-Region Geo-Testing with Residential Proxies","chrome-devtools-mcp-proxy-setup","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002Fchrome-devtools-mcp-proxy-setup.webp","2026-11-27T09:22:44.000Z","chrome-devtools-mcp proxy setup",{"name":20,"slug":20},[144,145],{"name":20,"slug":20,"visibility":21},{"name":29,"slug":30,"visibility":21},[147,162,174,186,198],{"id":148,"title":149,"slug":150,"feature_image":151,"published_at":152,"twitter_title":153,"primary_tag":154,"tags":155},"6aa1292f4956c90001bef44e","ProxySite.com Review (2026): Is It Safe? 5 Best Alternatives","proxysite-review-alternatives","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002FProxySite-Review-and--Alternatives-article-cover-image.webp","2026-09-09T10:16:50.000Z","proxysite",{"name":20,"slug":20},[156,157,160],{"name":20,"slug":20,"visibility":21},{"name":158,"slug":159,"visibility":21},"对比选型","comparisons",{"name":161,"slug":161,"visibility":21},"hot",{"id":163,"title":164,"slug":165,"feature_image":166,"published_at":167,"twitter_title":168,"primary_tag":169,"tags":170},"6a978f9a4956c90001bee8bb","BlockAway Alternatives: 6 Best Options (2026)","blockaway-alternatives","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F09\u002FBlockAway-Alternatives-article-cover-image.webp","2026-09-02T03:14:08.000Z","blockaway alternative",{"name":20,"slug":20},[171,172,173],{"name":20,"slug":20,"visibility":21},{"name":158,"slug":159,"visibility":21},{"name":161,"slug":161,"visibility":21},{"id":175,"title":176,"slug":177,"feature_image":178,"published_at":179,"twitter_title":180,"primary_tag":181,"tags":182},"6a912ce84956c90001bee35d","HTTPX vs Requests vs aiohttp: Features, Performance, and Python Use Cases","httpx-vs-requests-vs-aiohttp","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F08\u002FHTTPX-vs-Requests-vs-aiohttp-article-cover-image.webp","2026-08-28T07:27:34.000Z","httpx vs requests",{"name":20,"slug":20},[183,184,185],{"name":20,"slug":20,"visibility":21},{"name":158,"slug":159,"visibility":21},{"name":161,"slug":161,"visibility":21},{"id":187,"title":188,"slug":189,"feature_image":190,"published_at":191,"twitter_title":192,"primary_tag":193,"tags":194},"6a90fcea4956c90001bee256","8 Best Germany Proxies in 2026: Provider Comparison","best-germany-proxies","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F08\u002FBest-Germany-Proxies-article-cover-image.webp","2026-08-28T03:40:55.000Z","germany proxy",{"name":20,"slug":20},[195,196,197],{"name":20,"slug":20,"visibility":21},{"name":158,"slug":159,"visibility":21},{"name":161,"slug":161,"visibility":21},{"id":199,"title":200,"slug":201,"feature_image":202,"published_at":203,"twitter_title":204,"primary_tag":205,"tags":206},"6a8e92664956c90001beddc2","Bing Rank Tracker: Reliable Local SERP Monitoring Guide","bing-rank-tracker","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F08\u002F-------16.webp","2026-08-26T07:42:04.000Z","bing rank checker",{"name":20,"slug":20},[207,208,211],{"name":20,"slug":20,"visibility":21},{"name":209,"slug":210,"visibility":21},"应用场景","use-cases",{"name":161,"slug":161,"visibility":21},[213,226,237,248,259],{"id":214,"title":215,"slug":216,"feature_image":217,"published_at":218,"twitter_title":219,"primary_tag":220,"tags":221},"6b0946f492ab700001dc0920","Best Rotating Proxies in 2026 7 Rotating Proxy Providers Compared","best-rotating-proxies","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FBest-Rotating-Proxies-in-2026-7-Rotating-Proxy-Providers-Compared.webp","2026-11-27T09:07:09.000Z","best rotating proxies",{"name":20,"slug":20},[222,223],{"name":20,"slug":20,"visibility":21},{"name":224,"slug":225,"visibility":21},"排行榜","top-picks",{"id":227,"title":228,"slug":229,"feature_image":230,"published_at":231,"twitter_title":232,"primary_tag":233,"tags":234},"6b07a50492ab700001dc0603","How to Configure an NGINX Docker Reverse Proxy with Rola IP Egress","nginx-docker-reverse-proxy","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FHow-to-Configure-an-NGINX-Docker-Reverse-Proxy-with-Rola-IP-Egress-1.webp","2026-11-26T03:21:51.000Z","nginx docker reverse proxy",{"name":20,"slug":20},[235,236],{"name":20,"slug":20,"visibility":21},{"name":29,"slug":30,"visibility":21},{"id":238,"title":239,"slug":240,"feature_image":241,"published_at":242,"twitter_title":243,"primary_tag":244,"tags":245},"6b079b8692ab700001dc05ce","Android Proxy Settings for Mobile Network: The No-Root Guide (2026)","android-proxy-settings-mobile-network","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FAndroid-Proxy-Settings-for-Mobile-Network_-The-No-Root-Guide--2026-.webp","2026-11-26T03:10:40.000Z","android proxy settings mobile network",{"name":20,"slug":20},[246,247],{"name":20,"slug":20,"visibility":21},{"name":29,"slug":30,"visibility":21},{"id":249,"title":250,"slug":251,"feature_image":252,"published_at":253,"twitter_title":254,"primary_tag":255,"tags":256},"6b0655a092ab700001dc0440","Rammerhead Proxy: Setup, HTTP Upstreams and Alternatives","rammerhead-alternatives","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002Frammerhead-alternatives.webp","2026-11-25T03:59:48.000Z","Rammerhead Proxy",{"name":20,"slug":20},[257,258],{"name":20,"slug":20,"visibility":21},{"name":158,"slug":159,"visibility":21},{"id":260,"title":261,"slug":262,"feature_image":263,"published_at":264,"twitter_title":265,"primary_tag":266,"tags":267},"6b05417f92ab700001dc034d","ProxyEmpire Review (2026): Our Best Alternative for Predictable Bulk Residential Use","proxyempire-review","https:\u002F\u002Frola-ip.co\u002F__ghost__\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FProxyEmpire-Review--2026-_-Our-Best-Alternative-for-Predictable-Bulk-Residential-Use.webp","2026-11-24T08:12:53.000Z","proxyempire review",{"name":20,"slug":20},[268,269],{"name":20,"slug":20,"visibility":21},{"name":158,"slug":159,"visibility":21}]