Skip to content
Advertisement

requests.auth.AuthBase TypeError on call

From the docs at https://docs.python-requests.org/en/master/user/authentication/

I gathered that the __call__ function in my own Auth Class should have the r argument,

However when i go to call this class in requests.get(auth=MyClass), I get the error TypeError: __call__() missing 1 required positional argument: 'r'

The code for my class can be found here https://pastebin.com/YDZ2DeaT

JavaScript

I’ve tried using the example code, which works, but I can’t figure out why mine won’t work.

python-requests version is 2.25.1

Advertisement

Answer

I think I know what is going on.

This line instantiates an object, called TokenClass

JavaScript

then here,

JavaScript

you are calling that object like a function

when you call an object like a function, python looks for the __call__ method of the object.

And you are not calling in any arguments here. What you have is roughly the same as this I think

JavaScript

and so it complains that you are missing the r argument


This is their example:

JavaScript

MyAuth is a class that they define, and then MyAuth() creates an instance of it that they pass in to get.

Yours is more like this

JavaScript

It could also be written like this

JavaScript

This program with produce the same error you are getting

JavaScript

because when you put () after a class, you get an instance, and when you put () after an instance, you call the __call__ method

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement