Troubleshooting SSL Certificate Errors with Python Requests

Feb 3, 2024 ยท 2 min read

When using the Python Requests library to make HTTPS requests, you may encounter an error like:

SSLError: [SSL] LOCAL_ISSUER_CERT_NOT_TRUSTED

This error means that the SSL certificate presented by the server is not trusted by your local system. There are a few things you can try to resolve this:

Check your Operating System's Trust Store

Most operating systems come with a default set of trusted SSL certificate authorities. However, occasionally these can get out of date. Try updating your OS and see if that resolves the issue:

  • On Linux, use your package manager to update ca-certificates
  • On Windows or Mac, check for OS updates and install if available
  • Specify a Custom CA Bundle

    If updating the OS doesn't help, the next step is to specify your own set of trusted CA certificates.

    The Requests library allows you to pass in a custom CA bundle path:

    import requests
    
    resp = requests.get('https://example.com', verify='/path/to/ca/bundle')

    You can often find up-to-date CA bundles online to use for this purpose.

    Disable Certificate Verification

    As a last resort, you can disable SSL certificate verification entirely:

    resp = requests.get('https://example.com', verify=False)

    However this removes security, so only use as a temporary measure.

    Debugging SSL issues can be tricky! The key is to gradually narrow down the root cause - whether it's an OS issue, network configuration problem, or invalid certificate presented by the server you are accessing. Carefully going through these steps can help resolve these kinds of errors.

    Browse by tags:

    Browse by language:

    Tired of getting blocked while scraping the web?

    ProxiesAPI handles headless browsers and rotates proxies for you.
    Get access to 1,000 free API credits, no credit card required!