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())
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.79.20