#๐Ÿ”’ TypeError: 'set' object is not callable exception when using requests to form a request

15 messages ยท Page 1 of 1 (latest)

primal pumice
#

I'm trying to do something really simple. I'm just requesting an OAuth2 token from an endpoint, it's a very simple function:

def __get_access_token():
    response = requests.post(
        token_url,
        data={"grant_type": "client_credentials"},
        auth={client_id, client_secret}
    )
    return response.json()["access_token"]

However when I run it I get the exception (assume that token_url, client_id and client_secret are real values when executing):

Traceback (most recent call last):
  File "/home/x/.cache/JetBrains/RemoteDev/dist/8cfe3c6ce165d_pycharm-professional-2024.2.1/plugins/python-ce/helpers/pydev/pydevd.py", line 1557, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
...

  File "/home/x/PycharmProjects/wiiWeight/venv/lib/python3.12/site-packages/requests/models.py", line 602, in prepare_auth
    r = auth(self)
        ^^^^^^^^^^
TypeError: 'set' object is not callable

What exactly am I doing wrong here? I can't figure it out myself.
I'm running Python 3.12

lone flameBOT
#

@primal pumice

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

midnight fox
#

That's just not valid

primal pumice
#

I think I'm being really dumb because I don't understand what you mean, sorry

midnight fox
#

{client_id, client_secret} is a set

primal pumice
#

Oh so I have to put them in explicitly, and not read them from a config file as variables?

midnight fox
#

Where did I say anything about config files

primal pumice
#

You didn't, but that's how I'm pulling out the values so they're not hardcoded into the source

midnight fox
#

Right but you put them into a set after getting them

#

You need to put them into one of the classes from requests.auth

primal pumice
#

Thanks, that's a lot clearer now

lone flameBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.