Got ERR_TUNNEL_CONNECTION_FAILED in Chrome and no idea why? Try the same proxy from Python, because it'll tell you what the browser won't. Chromium drops every CONNECT reply except 200 and 407, so you can't tell a policy block from a dead exit in there.

Python leaves the status in the exception text. You'll see OSError: Tunnel connection failed: 502 Bad Gateway from http.client, and requests wraps that in a ProxyError with the same words inside.

I'd read that string before retrying anything, since a blanket except ProxyError plus a retry loop just burns time on errors that can't heal. A 403 is usually policy, sometimes just a port they don't allow. 407 means check your login. If you get 405 or 501 you aren't talking to a forward proxy at all. Only 502, 503 and 504 are worth backing off on, those happened behind the proxy.

Disclosure: we run a proxy service, none of this depends on whose.

you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 2 days ago (1 child)

Consider using a more serious browser; Firefox is freely available. I say this as a former ChromiumOS contributor. Also, curl is quite the useful tool and doesn't require writing a custom Python script. I say that as a Python user.

Also, please don't use chatbots to format your posts. Write your own posts using your own voice, please; we can tell the difference.

  • source
  • hideshow 1 child comment