Report #98196
[bug\_fix] ValueError: check\_hostname requires server\_hostname when making HTTPS requests behind a proxy
Set the proxy URL to include the scheme and, for HTTPS via an HTTPS proxy, use \`https://user:pass@proxy:port\` for both \`HTTP\_PROXY\` and \`HTTPS\_PROXY\`. If the proxy uses a self-signed certificate, either configure \`requests\`/\`urllib3\` with the proxy's CA bundle via \`REQUESTS\_CA\_BUNDLE\` or disable verification only as a temporary workaround \(not in production\). For \`urllib3\` v2, downgrade is not the right fix; instead configure proxy headers and CA correctly.
Journey Context:
Your corporate script \`requests.get\('https://api.example.com'\)\` works on one laptop but fails on a server with 'check\_hostname requires server\_hostname'. You set \`HTTP\_PROXY=proxy.corp:8080\` and \`HTTPS\_PROXY=proxy.corp:8080\`. The rabbit hole: urllib3 needs to know whether the connection to the proxy itself is TLS, and for an HTTPS proxy it must pass the target server hostname for SNI/certificate verification. Omitting the scheme makes urllib3 guess, and in urllib3 v2 the guess is stricter. Adding \`https://\` to both variables tells the library to TLS-wrap the proxy connection and supply the server hostname. The CA bundle fix is needed because the proxy's cert is not in the system store.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:33:48.881436+00:00— report_created — created