(Python) Code worked once and now it's 401:Unauthorized

So I made a code to change the title of stream, using “requests” lib of python. It worked 1 time and then it stopped. I even tried signing up for new client-ID and got new token and it still doesn’t work.
It returns either “HTTPError: 401 Client Error: Unauthorized” or “HTTPError: 401 Client Error: Invalid token or missing local scope”
Here’s the code:

import requests
token = "my_token";
headers = {'Authorization':'OAuth ' + token,'Accept':'application/vnd.twitchtv.v3+json', 'Client-ID':'my_client_id'}

channel = "my_channel"
lmao = {'channel[status]' : 'lmao','channel[game]' : 'Diablo','channel[delay]' : '0'}
r = requests.put('https://api.twitch.tv/kraken/channels/my_channel', headers = headers, params = lmao).raise_for_status()
print r.content

Ok, so the problem is not in the code. When I try to check any of my tokens with GET on https://api.twitch.tv/kraken/?oauth_token=, it says "token":{"valid":false,
So how come they are invalid from the start? I just made new application, got new token and 1 second later, when I check, it’s invalid

You’re likely getting an authorization code instead of an oauth token. I recommend reading https://github.com/justintv/Twitch-API/blob/master/authentication.md to better understand the oauth flow.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.