Get Live Streams return bad content

link = '' + temp
accept = 'application/vnd.twitchtv.v5+json'
client_id = 'xxxxxxxxxxxxxxxxxxxxxxx'
async with aiohttp.ClientSession() as session:
   async with session.get(link, headers={'Client-ID': client_id, 'Accept': accept}) as r:
     if r:
       rj = await r.json(content_type=None)
         if rj['streams']:

Sometimes I get this error KeyError: 'streams', why is that? Should this request return always the streams array? I’m having this error in these last few days, never had problem of this kind in past months.

This is probably related to

You are getting a non 200 error code and you are not testing for the error code, just trying to parse the JSON.

if the response is an error then you won’t get a streams key in the JSON

Gotcha, I was sure that checking if r: was enough, now I’m adding if r and r.status == 200: then it should be working fine. Thanks

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