Scraping SSL CERTIFICATE_VERIFY_FAILED error for http//en.wikipedia.org
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When attempting to scrape content from websites such as http://en.wikipedia.org using Python's `urllib`, `requests`, or other HTTP libraries, users may encounter an error labeled as `SSL: CERTIFICATE_VERIFY_FAILED`. This error is particularly common when the target server requires the use of SSL/TLS for secure communication, and something isn't perfectly right with the configuration or validation of the certificate on the client side. Below, we'll delve into why this error occurs and the steps to resolve it, drawing on practical examples and clarifications.
Understanding SSL/TLS Certificates
SSL (Secure Sockets Layer) and its successor, TLS (Transport Layer Security), are cryptographic protocols designed to provide secure communication over a computer network. Websites with HTTPS make use of these protocols to encrypt data before it is sent over the internet, ensuring privacy and integrity.
A website's SSL/TLS certificate is issued by a trusted Certificate Authority (CA). This certificate verifies the identity of the website and enables encrypted communication. When a client (like a web browser or a script) attempts to connect to the server over HTTPS, it must first verify the server's certificate to ensure the connection is secure.
Common Causes of `CERTIFICATE_VERIFY_FAILED`
The `CERTIFICATE_VERIFY_FAILED` error occurs when a client's verification of the server's certificate fails. Here are some common causes:
- Expired Certificates: The server's certificate may have expired and become invalid.
- Untrusted Certificate Authority: The certificate may be issued by a CA that is not recognized by the client.
- Self-signed Certificates: The server is using a certificate it signed itself.
- Incorrect System Clock: The client’s system clock might be incorrect, causing issues with verifying the certificate's validity period.
- Absent or Outdated Root Certificates: The client might not have the CA's root certificate or, if it does, it might be outdated.
Troubleshooting Steps
1. Verify the System Date and Time
Ensure that the system's date and time settings are accurate. An incorrect system clock can lead to the failure of certificate expiry checks.
Related reading
- Search with a mask
- seccompunconfined for a container in a kubernetes pod? Or changing default in docker 1.10?
- SecItemAdd and SecItemCopyMatching returns error code -34018 errSecMissingEntitlement
- Secure hash and salt for PHP passwords
- Script blocks on thread when executing a python script, but not in interactive mode
- Seaborn heatmap not showing columns converted from string to numerical
- Second and Third Distributed Kafka Connector workers failing to work correctly
- See full command of running/stopped container in Docker

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.