The problem you are having is caused by an untrusted SSL certificate.
Like dirk mentioned in a previous comment, the quickest fix is setting verify=False:
requests.get('https://example.com', verify=False)
Please note that this will cause the certificate not to be verified. This will expose your application to security risks, such as man-in-the-middle attacks.
Of course, apply judgment. As mentioned in the comments, this may be acceptable for quick/throwaway applications/scripts, but this should really not go to production software.
If just skipping the certificate check is not acceptable in your particular context, consider the following options, your best option is to set the verify parameter to a string that is the path of the .pem file of the certificate (which you should obtain by some sort of secure means).
So, as of version 2.0, the verify parameter accepts the following values, with their respective semantics:
True: causes the certificate to validated against the library's own trusted certificate authorities (Note: you can see which root certificates (RCs) Requests uses via the Certifi library, a trust database of RCs extracted from Requests: Certifi - Trust Database for Humans).False: bypasses certificate validation completely.Path to a CA_BUNDLE file for Requests to use to validate the certificates.
Source: Requests - SSL Cert Verification
Also take a look at the cert parameter on the same page.
The problem you are having is caused by an untrusted SSL certificate.
Like dirk mentioned in a previous comment, the quickest fix is setting verify=False:
requests.get('https://example.com', verify=False)
Please note that this will cause the certificate not to be verified. This will expose your application to security risks, such as man-in-the-middle attacks.
Of course, apply judgment. As mentioned in the comments, this may be acceptable for quick/throwaway applications/scripts, but this should really not go to production software.
If just skipping the certificate check is not acceptable in your particular context, consider the following options, your best option is to set the verify parameter to a string that is the path of the .pem file of the certificate (which you should obtain by some sort of secure means).
So, as of version 2.0, the verify parameter accepts the following values, with their respective semantics:
True: causes the certificate to validated against the library's own trusted certificate authorities (Note: you can see which root certificates (RCs) Requests uses via the Certifi library, a trust database of RCs extracted from Requests: Certifi - Trust Database for Humans).False: bypasses certificate validation completely.Path to a CA_BUNDLE file for Requests to use to validate the certificates.
Source: Requests - SSL Cert Verification
Also take a look at the cert parameter on the same page.
From Requests' documentation on SSL verification:
Requests can verify SSL certificates for HTTPS requests, just like a web browser. To check a host’s SSL certificate, you can use the verify argument (for example, interactively):
requests.get('https://kennethreitz.com', verify=True)
If you don't want to verify your SSL certificate, make verify=False
SSL errors in python 3.13
Python API SDK SSL: CERTIFICATE_VERIFY_FAILED Error
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain
"SSL: CERTIFICATE_VERIFY_FAILED" error on Python 3.9.6 (Windows 10)
What does CERTIFICATE_VERIFY_FAILED mean in Python?
Does updating Python fix SSL certificate errors?
Why does Python reject valid SSL certificates?
Videos
I'm getting an SSL error every time I make a request with a proxy. At first I thought the problem was SSL related, but i found some code than implements the proxy using urllib's build opener method and it works just fine. So I'm wondering how I can fix the error using requests library since I'm working on a big project that uses a requests session. BTW I'm using Luminati proxy manger.
My code for requests session:
sess = requests.session()
sess.proxies.update({'http': 'http://127.0.0.1:24000',
'https': 'http://127.0.0.1:24000'})
resp = sess.get('https://api.myip.com')The error i get:
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.myip.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
The code i found online that works just fine:
from urllib import request
opener = request.build_opener(
request.ProxyHandler({'http': 'http://127.0.0.1:24000',
'https': 'http://127.0.0.1:24000'}))
print(opener.open('https://api.myip.com').read()) Thank you in advance