O'Reilly logo

Python Requests Essentials by Bala Subrahmanyam Varanasi, Rakesh Vidya Chandra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Verifying an SSL certificate with Requests

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', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required