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:

    The easiest way to do Web Scraping

    Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


    Try ProxiesAPI for free

    curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

    <!doctype html>
    <html>
    <head>
        <title>Example Domain</title>
        <meta charset="utf-8" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
    ...

    X

    Don't leave just yet!

    Enter your email below to claim your free API key: