I got by authentification - user id, client_id
Then i am trying to get by helix method, in broadcaster id i set user id.
But i got 404
headers = {
"Authentification": "Bearer token",
"Client_id": client_id}
stream_key = requests.get('https://api.twitch.tv/helix/stream', params = {'broadcaster_id': user_id}, headers=headers).json()
It’s https://api.twitch.tv/helix/streams/key
Yes sure, i use that link, i am from phone typed code
Others ideas why it doesnt work
Dist
7
Log the exact request you’re making, as a 404 would indicate you’re URL is incorrect. If you also log the body of the response and not just the status code that should also give you the full error.
I will paste, when i am at home
There is nothing obviously wrong from your screenshot
And I cannot copy and paste from the screenshot to test it in python
flekser
12
import requests
import time
class Twitch:
def init(self, oauth: str):
self.oauth = oauth
self.headers = {
‘Authorization’: 'Bearer ’ + self.oauth,
}
def get_stream_key(self):
client_id = requests.get('https://id.twitch.tv/oauth2/validate', headers=self.headers).json()['client_id']
id = requests.get('https://id.twitch.tv/oauth2/validate', headers=self.headers).json()['user_id']
headers = {
'Authorization': 'Bearer ' + self.oauth,
'Client-Id': client_id
}
qqq = requests.get('https://api.twitch.tv/helix/streams/key',
params={'broadcaster_id': id},
headers=headers).json()
print(qqq)
return qqq
def get_key():
with open('tokens.txt', 'r') as f:
tokens = f.read().splitlines()
i = 1
for token in tokens:
try:
stream_key = Twitch(token).get_stream_key()
headers = {
'Authorization': 'Bearer ' + token
}
print(str(i)+' ---- ' + requests.get('https://id.twitch.tv/oauth2/validate', headers=headers).json()['login'] + ' ----')
print(stream_key)
with open('stream_key.txt', 'a') as f:
f.write(stream_key + f':push rtmp://live-ams.twitch.tv/app/{stream_key};'+ '\n')
except Exception as e:
print(e)
time.sleep(1)
i += 1
input()
input()
input()
Twitch.get_key()
I distilled your code down to
import requests
oauth = 'TESTTOKEN';
headers = {
'Authorization': 'Bearer ' + oauth
}
client_id = requests.get('https://id.twitch.tv/oauth2/validate', headers=headers).json()['client_id']
id = requests.get('https://id.twitch.tv/oauth2/validate', headers=headers).json()['user_id']
headers = {
'Authorization': 'Bearer ' + oauth,
'Client-Id': client_id
}
qqq = requests.get('https://api.twitch.tv/helix/streams/key',
params={'broadcaster_id': id},
headers=headers).json()
print(qqq)
And I was able to obtain a stream key.

I cannot find a problem with your code. No 404 was returned and my stream key was obtained
flekser
15
i dont understand really, what happens
Looks like some some of environemental issue running the code your side.
There doesn’t seem to be anything incorrect
flekser
17
but 2 first requests is going to be OK, why the last one give this …
No idea. thats up to you to debug whats wrong with your environment, routing or something else.
The first calls are to id.twitch.tv the second to api.twitch.tv clutching at straws: did you hostfile api.twitch.tv somewhere else and it’s 404’ing since it’s not actually going to Twitch?
The problem needs to be traceed with/from your machine, as the code works fine on my machine
flekser
19
I was trying on dedicated server, what python version do u have?
python3
But the version should be irrelevant since this wouldn’t cause a 404