# Get Live Streams return bad content

**URL:** <https://discuss.dev.twitch.com/t/get-live-streams-return-bad-content/25036>\
**Category:** API\
**Created:** [April 18, 2020, 3:36am UTC](https://discuss.dev.twitch.com/t/get-live-streams-return-bad-content/25036 "2020-04-18T03:36:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheKill\_996](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/thekill_996/32/6901_2.png) [@TheKill\_996](https://discuss.dev.twitch.com/u/TheKill_996)\
**Post date:** [April 18, 2020, 3:36am UTC](https://discuss.dev.twitch.com/t/get-live-streams-return-bad-content/25036/1 "2020-04-18T03:36:47Z")

</div>

```
link = 'https://api.twitch.tv/kraken/streams/?channel=' + 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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 18, 2020, 9:56am UTC](https://discuss.dev.twitch.com/t/get-live-streams-return-bad-content/25036/2 "2020-04-18T09:56:56Z")

</div>

This is probably related to

> [@Intermittent Error 400 (Invalid Cursor) from Helix Streams API](https://discuss.dev.twitch.com/t/intermittent-error-400-invalid-cursor-from-helix-streams-api/25035):
>
> Around 12:30 PST I began seeing errors with pagination on the Helix Streams endpoint. Here is the response: Body: {"error":"Bad Request","status":400,"message":"invalid cursor"} Here was the chain of pagination before hitting the error: https://api.twitch.tv/helix/streams?first=100&type=all https://api.twitch.tv/helix/streams?first=100&type=all&after=ZXlKeklqbzVOakl5Tmk0MU5Ua3hNemszT1RreU1pd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkgZXlKeklqbzFNek0zTGpRNE1qSTFOakEwTWprME5pd2laQ0k2Wm1Gc2MyVXNJblFpT25Se…

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

---

<div class="post-metadata">

**Author:** ![TheKill\_996](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/thekill_996/32/6901_2.png) [@TheKill\_996](https://discuss.dev.twitch.com/u/TheKill_996)\
**Post date:** [April 18, 2020, 1:23pm UTC](https://discuss.dev.twitch.com/t/get-live-streams-return-bad-content/25036/3 "2020-04-18T13:23:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [May 18, 2020, 1:27pm UTC](https://discuss.dev.twitch.com/t/get-live-streams-return-bad-content/25036/4 "2020-05-18T13:27:12Z")

</div>

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