votes up 1

Auth hooks must be callable.

Package:
Exception Class:
NotImplementedError

Raise code

    return authstr


class AuthBase(object):
    """Base class that all auth implementations derive from"""

    def __call__(self, r):
        raise NotImplementedError('Auth hooks must be callable.')


class HTTPBasicAuth(AuthBase):
    """Attaches HTTP Basic Authentication to the given Request object."""

    def __init__(self, username, password):
        self.username = username

Ways to fix

votes up 0 votes down

Summary:

The auth hook must be callable. i.e the call magic method for the AuthBase class must be defined

Reproduce

from requests.auth import AuthBase
import requests
class ExampleAuth(AuthBase): #__call__ not defined
    def __init__(self, username):
        self.username = username

requests.get('http://example.org', auth=ExampleAuth('lobh')

Fix:

from requests.auth import AuthBase
import requests
class ExampleAuth(AuthBase): # __call__ is defined
    def __init__(self, username):
        self.username = username 
    def __call__(self, r): 
        r.headers['X-Auth'] = self.username 
        return r
requests.get('http://example.org', auth=ExampleAuth('lobh')

Jun 02, 2021 cRyp70s answer
cRyp70s 113

Add a possible fix

Please authorize to post fix