[Python] Python requests failed to verify certificate, while urllib3 and curl do it...

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    Trying to done simple GET request. Site have self-signed certificate. I was export it using Firefox (downloaded chained certificates) as a "pem" file. Here versions of libraries:

    [user@host]$ pip list | grep -E "urllib3|requests"
    requests 2.32.4
    urllib3 2.5.0


    This is code that using requests:

    import requests
    requests.get("https://bvs.skala", verify='/home/user/bvs-skala-chain.pem')


    And got next error:

    requests.exceptions.SSLError: HTTPSConnectionPool(host='bvs.skala', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:979)')))


    This is code that use same certificate, but urllib3 instead of requests:

    import urllib3
    http = urllib3.PoolManager(ca_certs='/home/user/bvs-skala-chain.pem')
    response = http.request('GET', 'https://bvs.skala/')
    print(response.status)


    And it is runs successfully:

    [user@host]$ python using_urllib3.py
    200


    And curl is runs successfully too:

    [user@host]$ curl -X GET https://bvs.skala --cacert /home/user/bvs-skala-chain.pem
    <!doctype html>
    <html>
    <head>
    ...


    What else was tried, but without success:

    export REQUESTS_CA_BUNDLE=/home/user/bvs-skala-chain.pem
    export CURL_CA_BUNDLE=/home/user/bvs-skala-chain.pem


    Can't figure out where to dig.

    Continue reading...

Compartilhe esta Página