Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: invalid_auth in requests.post('https://slack.com/api/auth.test', data = {'token': token}) with users.list #2

Open
skolaautomat opened this issue May 14, 2021 · 5 comments

Comments

@skolaautomat
Copy link

I just downloaded your script and it gives an error when trying a retrieve_data('users.list', PAYLOAD).

Any idea about what is happening here?

Thanks.

@margaritageleta
Copy link
Owner

Could you provide the full traceback?

@annazolkieve
Copy link

$ python3 slack.py --token xoxp-XXX
Successfully authenticated for team XXX (ID 000) and user XXX (ID XXX)
Status code: 200
Data retrieved OK. Status code: 200
Error: invalid_auth
Traceback (most recent call last):
  File "slack.py", line 143, in <module>
    users = fetch_users()
  File "slack.py", line 45, in fetch_users
    with open('users.list.json') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'users.list.json'

@annazolkieve
Copy link

users.list returns invalid_auth while previously telling Successfully authenticated.

@annazolkieve
Copy link

annazolkieve commented Jul 19, 2021

You need to send Authorization token inside headers. Earlier we were passing the token along with the query params but according to the latest documentation on slack, now we need to send it in headers only.

Source: slackapi/python-slack-sdk#302 (comment)

So:
before:

        PAYLOAD = {
            'token': args.token,
        }
requests.get(f'https://slack.com/api/conversations.history', params = payload)`

after:

        PAYLOAD = {}
headers = {'Authorization': 'Bearer ' + token, 'Content-type': 'application/x-www-form-urlencoded'}
requests.get(f'https://slack.com/api/conversations.history', params = payload, headers=headers)`

@annazolkieve
Copy link

Also: https://api.slack.com/methods/users.list:

Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants