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

Custom authentication

Requests also provides the ability to write a new or custom authentication based on the user's needs and flexibility. It is equipped with requests.auth.AuthBase class which is a base class for all the authentication types. This can be achieved by implementing the custom authentication in the __call__() of requests.auth.AuthBase.

Let us take a look at its syntax:

>>> import requests
>>> class CustomAuth(requests.auth.AuthBase):
...     def __call__(self, r):
...         # Custom Authentication Implemention
...         return r
...
>>> requests.get('https://demo.example.com/resource/path',
... auth=CustomAuth())

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