slack-export-history icon indicating copy to clipboard operation
slack-export-history copied to clipboard

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

Open skolaautomat opened this issue 3 years ago • 5 comments

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.

skolaautomat avatar May 14 '21 00:05 skolaautomat

Could you provide the full traceback?

margaritageleta avatar May 24 '21 15:05 margaritageleta

$ 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 avatar Jul 19 '21 11:07 annazolkieve

users.list returns invalid_auth while previously telling Successfully authenticated.

annazolkieve avatar Jul 19 '21 12:07 annazolkieve

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: https://github.com/slackapi/python-slack-sdk/issues/302#issuecomment-805465474

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 avatar Jul 19 '21 12:07 annazolkieve

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.

annazolkieve avatar Jul 19 '21 12:07 annazolkieve