When I use:
import requests
r = requests.get("https://example.com")
I get the following exception:
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)
However, If i use following code:
url = "https://www.example.com"
request = urllib.request.urlopen(url)
It gives me the correct response[200] code. Why is it so? What is the difference between these two methods and which one should be preferred?
Use the former one:
I will add the source of why it's better.
Anyways you need to set verify
as False
to prevent requests from verifying SSL certificates for HTTPS requests:
import requests
r = requests.get("https://example.com", verify=False)
Edit:
Difference between requests.get() and urllib.request.urlopen() python
What are the differences between the urllib, urllib2, and requests module?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With