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