python network_error ai_generated true

requests.exceptions.SSLError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate does not match 'example.com'')))

ID: python/requests-sslerror-wrong-hostname

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-01-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

The server's SSL certificate is issued for a different hostname than the one being accessed.

generic

中文

服务器的SSL证书是为与正在访问的主机名不同的主机名颁发的。

Workarounds

  1. 95% success Use the correct hostname that matches the certificate's Common Name or Subject Alternative Names
    requests.get('https://correct-hostname.com')
  2. 85% success Provide the certificate via verify parameter if the server uses a custom CA
    requests.get('https://example.com', verify='/path/to/custom-ca.pem')

Dead Ends

Common approaches that don't work:

  1. Setting verify=False to ignore SSL verification entirely 70% fail

    Disabling SSL verification exposes the connection to man-in-the-middle attacks and does not solve the hostname mismatch for valid certificates.

  2. Updating the requests library to the latest version 90% fail

    The issue is not a library bug but a certificate configuration problem on the server side.