Requests provides the facility to verify an SSL certificate for HTTPS requests. We can use the verify
argument to check whether the host's SSL certificate is verified or not.
Let us consider a website which has got no SSL certificate. We shall send a GET request with the argument verify
to it.
The syntax to send the request is as follows:
requests.get('no ssl certificate site', verify=True)
As the website doesn't have an SSL certificate, it will result an error similar to the following:
requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))
Let us verify the SSL certificate for a website which is certified. Consider the following example:
>>> requests.get('https://python.org', verify=True) <Response [200]>
In the preceding example, the result was 200,
as the mentioned website is SSL certified one.
If we do not want to verify the SSL certificate with a request, then we can put the argument verify=False
. By default, the value of verify
will turn to True
.
18.119.163.238