Httpx: The handshake operation timed out - On requests https requests

Created on 21 Dec 2020  Â·  4Comments  Â·  Source: encode/httpx

Checklist

Wasn't able to find help in Issues or a solution Pull requests.

Describe the bug

Error while requesting on any site via HTTPS.
HTTP works, but I need HTTPS for what I'm planning to do.

To reproduce

# User/Pass Proxy
proxy = {
    'http://': 'http://{0}:{1}@{2}:{3}'.format(splitted[2], splitted[3], splitted[0], splitted[1]),
    'https://': 'https://{0}:{1}@{2}:{3}'.format(splitted[2], splitted[3], splitted[0], splitted[1])
}
c = httpx.Client(proxies=proxy)
response = c.get("https://ipinfo.io/json").text
print(response)

Actual behavior

Error:

httpx.ProxyError: _ssl.c:1091: The handshake operation timed out

Debugging material

Traceback (most recent call last):
  File "D:\x\venv\lib\site-packages\httpcore\_sync\http_proxy.py", line 217, in _tunnel_request
    ) = proxy_connection.request(
  File "D:\x\venv\lib\site-packages\httpcore\_sync\connection.py", line 93, in request
    self.socket = self._open_socket(timeout)
  File "D:\x\venv\lib\site-packages\httpcore\_sync\connection.py", line 119, in _open_socket
    return self.backend.open_tcp_stream(
  File "D:\x\venv\lib\site-packages\httpcore\_backends\sync.py", line 143, in open_tcp_stream
    return SyncSocketStream(sock=sock)
  File "C:\Program Files\Python38\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "D:\x\venv\lib\site-packages\httpcore\_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore.ConnectTimeout: _ssl.c:1091: The handshake operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\x\venv\lib\site-packages\httpx\_exceptions.py", line 326, in map_exceptions
    yield
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 861, in _send_single_request
    (status_code, headers, stream, ext) = transport.request(
  File "D:\x\venv\lib\site-packages\httpcore\_sync\http_proxy.py", line 124, in request
    return self._tunnel_request(
  File "D:\x\venv\lib\site-packages\httpcore\_sync\http_proxy.py", line 242, in _tunnel_request
    raise ProxyError(exc)
httpcore.ProxyError: _ssl.c:1091: The handshake operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:/x/test.py", line 22, in <module>
    response = c.get("https://ipinfo.io/json").text
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 907, in get
    return self.request(
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 733, in request
    return self.send(
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 767, in send
    response = self._send_handling_auth(
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 805, in _send_handling_auth
    response = self._send_handling_redirects(
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 837, in _send_handling_redirects
    response = self._send_single_request(request, timeout)
  File "D:\x\venv\lib\site-packages\httpx\_client.py", line 861, in _send_single_request
    (status_code, headers, stream, ext) = transport.request(
  File "C:\Program Files\Python38\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "D:\x\venv\lib\site-packages\httpx\_exceptions.py", line 343, in map_exceptions
    raise mapped_exc(message, **kwargs) from exc  # type: ignore
httpx.ProxyError: _ssl.c:1091: The handshake operation timed out

Environment

  • OS: Windows
  • Python version: 3.8.0
  • HTTPX version: 0.16.1
  • HTTP proxy: yes - issue doesnt happen without proxy
  • Custom certificates: no

Additional context

Thanks in advance, hope anyone can help!

duplicate

Most helpful comment

Your proxy likely doesn't support HTTPS. Change the scheme of your https proxy to "http://{0}...", instead of "https://{0}...".

All 4 comments

@FlorianREGAZ Hi!

We just discussed a very similar issue earlier this morning: #1412 — that was also reporting httpx.ConnectTimeout: _ssl.c:1029: The handshake operation timed out on HTTPS requests.

TL;DR: you probably want to do this instead…

proxy = 'http://{0}:{1}@{2}:{3}'.format(splitted[2], splitted[3], splitted[0], splitted[1])

That is, use the same http:// proxy URL for both HTTP and HTTPS requests. See this comment for details and links: https://github.com/encode/httpx/issues/1412#issuecomment-748898324

Your proxy likely doesn't support HTTPS. Change the scheme of your https proxy to "http://{0}...", instead of "https://{0}...".

^Ditto.

I'm starting a "Troubleshooting" docs page so we can track these "common issues & solutions" there.

Thanks! Issue solved. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sethmlarson picture sethmlarson  Â·  5Comments

florimondmanca picture florimondmanca  Â·  4Comments

iwoloschin picture iwoloschin  Â·  4Comments

szelenka picture szelenka  Â·  4Comments

tomchristie picture tomchristie  Â·  4Comments