python network_error ai_generated true

httpx.ConnectError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123) while connecting to 'http://api.example.com'

ID: python/httpx-connecterror-ssl-wrong-version

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-10-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Attempting to use HTTPS on a plain HTTP port, or vice versa, causing SSL handshake failure.

generic

中文

尝试在普通HTTP端口上使用HTTPS,反之亦然,导致SSL握手失败。

Workarounds

  1. 95% success Use the correct protocol (http vs https) matching the server configuration
    httpx.get('http://api.example.com')  # if server uses HTTP, not HTTPS
  2. 90% success Use the correct port explicitly
    httpx.get('https://api.example.com:443')  # ensure port 443 for HTTPS

Dead Ends

Common approaches that don't work:

  1. Disabling SSL verification 80% fail

    The issue is not certificate validation but protocol mismatch; disabling SSL does not help.

  2. Using a different SSL/TLS version in the client 90% fail

    The server likely does not support SSL on that port at all.