Skip to content

Instantly share code, notes, and snippets.

@yashodhank
Created September 26, 2023 10:08
Show Gist options
  • Save yashodhank/a2b8caa1c708ed6e9d6cd3cdd5ae0ca2 to your computer and use it in GitHub Desktop.
Save yashodhank/a2b8caa1c708ed6e9d6cd3cdd5ae0ca2 to your computer and use it in GitHub Desktop.
urllib.error.URLError; <urlopen error [SSL: CERTIFICATE _VERIFY _FAILED] certificate verify failed; unable to get local issuer certificate (_ss1.c:1051)>

The error message indicates that the program is facing an SSL certificate verification error while trying to open a URL. This error occurs because the SSL certificate of the site that the program is trying to access cannot be verified by a local Certificate Authority (CA).

Here’s a step-by-step guide to help you resolve the SSL certificate error:

Step 1: Update CA Certificates

Firstly, ensure that the CA certificates on your system are up to date. You can do this by updating the certifi package using pip:

pip install --upgrade certifi

Step 2: Set Environment Variable

You can set the SSL_CERT_FILE environment variable to point to the updated CA bundle file, which is usually located in the certifi package directory. The exact path may vary depending on your system and Python installation.

You can find the path to the cacert.pem file in Python using:

import certifi
print(certifi.where())

Once you have the path, set the SSL_CERT_FILE environment variable:

export SSL_CERT_FILE=/path/to/cacert.pem  # For Linux/MacOS
set SSL_CERT_FILE=C:\path\to\cacert.pem  # For Windows

Step 3: Bypass SSL Verification (Not Recommended)

If updating the CA certificates does not solve the problem, you could bypass SSL certificate verification altogether. However, this approach is not recommended as it makes your connection insecure.

To bypass SSL certificate verification, you can modify the part of your code where you are making the request to the server to not verify the SSL certificate:

import ssl
import urllib.request

# Create an insecure context
context = ssl._create_unverified_context()

# Use the insecure context when making a request
response = urllib.request.urlopen(url, context=context)

Step 4: Update Chromedriver Autoinstaller

Additionally, it appears that there is an issue with the chromedriver_autoinstaller package. Ensure that you are using the latest version of this package:

pip install --upgrade chromedriver-autoinstaller

Step 5: Debugging

If none of the above solutions work, consider adding more logging and debugging information to your code to identify exactly where and why the SSL verification is failing.

Step 6: Recheck your code

Lastly, please ensure there are no typos or syntactical errors in your code, as the shared error log contains multiple typos and missing characters, which might be contributing to the issue.

After following these steps, try running your program again to see if the issue is resolved. If you continue to encounter issues, please provide any additional error messages or details you receive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment