slack-export-history
slack-export-history copied to clipboard
Error: invalid_auth in requests.post('https://slack.com/api/auth.test', data = {'token': token}) with users.list
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.
Could you provide the full traceback?
$ 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'
users.list
returns invalid_auth
while previously telling Successfully authenticated
.
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)`
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.