How to fix Python requests SSLError?

by scrapecrow Dec 19, 2022

SSLError error is seen when using Python requests module to scrape pages with untrusted SSL certificates.

import requests
response = requests.get("http://example.com/")
# raises: 
# SSLError: HTTPConnectionPool(host='example.com', port=80)...

# we can disable certificate verficiation (note: dangerous as it disables e2e encryption)
response = requests.get("http://example.com/", verify=False)
# or specify certficate file explicitly (.rem)
cert_location = "certificates/example-com-certificate.pem"
response = requests.get("http://example.com/", verify=cert_location)

The SSLError exception is rarely encountered in web scraping but the easiest way to fix it is to simply disable certification verification (verify=False parameter) if no sensitive data is being exchanged.

Note if manual fix is required the SSL certificates requests is using can be found using the requests.certs.where() method:

import requests
print(requests.certs.where())
'/etc/ssl/certs/ca-certificates.crt'  # example on Linux

This value can also be overridden using REQUESTS_CA_BUNDLE environment variable:

$ export REQUESTS_CA_BUNDLE="/etc/ssl/certs/my-certificates.pem" 
$ python -c "import requests;print(requests.certs.where())"
/ets/ssl/certs/my-certificates.pem

Finally, requests is using certifi to handle all SLL certificate-related operations - try updating it: pip install certifi --upgrade

Related Articles

Guide to Python requests POST method

Discover how to use Python's requests library for POST requests, including JSON, form data, and file uploads, along with response handling tips.

PYTHON
REQUESTS
HTTP
Guide to Python requests POST method

Guide to Python Requests Headers

Our guide to request headers for Python requests library. How to configure and what do they mean.

PYTHON
REQUESTS
HTTP
Guide to Python Requests Headers

How to Scrape YouTube in 2025

Learn how to scrape YouTube, channel, video, and comment data using Python directly in JSON.

SCRAPEGUIDE
PYTHON
HIDDEN-API
How to Scrape YouTube in 2025

Guide to List Crawling: Everything You Need to Know

In-depth look at list crawling - how to extract valuable data from list-formatted content like tables, listicles and paginated pages.

CRAWLING
BEAUTIFULSOUP
PYTHON
Guide to List Crawling: Everything You Need to Know

How to Find All URLs on a Domain

Learn how to efficiently find all URLs on a domain using Python and web crawling. Guide on how to crawl entire domain to collect all website data

CRAWLING
PYTHON
How to Find All URLs on a Domain

How to Capture and Convert a Screenshot to PDF

Quick guide on how to effectively capture web screenshots as PDF documents

SCREENSHOTS
PYTHON
NODEJS
How to Capture and Convert a Screenshot to PDF