# The api output bounces alot

**URL:** <https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809>\
**Category:** API\
**Created:** [October 15, 2016, 8:42pm UTC](https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809 "2016-10-15T20:42:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mateuszdrwal](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mateuszdrwal](https://discuss.dev.twitch.com/u/mateuszdrwal)\
**Post date:** [October 15, 2016, 8:42pm UTC](https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809/1 "2016-10-15T20:42:58Z")

</div>

i am trying to make some python code detect the start and end of a stream. here is what i got so far:

```
def streamStart():
    print("stream Start")

def streamStop():
    print("stream Stop")

def streamCheck():
    global status,info
    while True:
        info = json.loads(urlopen("https://api.twitch.tv/kraken/streams/%s?client_id=<my id>"%channel, timeout = 15).read().decode('utf-8'))
        if info.get("stream") == None:
            if status == True:
                streamStop()
            status = False
        else:
            if status == False:
                streamStart()
            status = True
status = False
streamCheck()

```

the problem im having is that when i do start streaming it takes it about two minutes to detect it (including delay) and when it does detect it i get this output:

```
stream Start
stream Stop
stream Start

```

and when i stop streaming i get the same type of bounce but this time 11 times and 5 minutes after i stopped:

```
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop
stream Start
stream Stop

```

this is really ennoying and i dont want to deal with it. i can confirm that this is not a bug in my code as if i refresh my browser with the api link i can also see it changing from refresh to refresh.  
im wondering if anybody else has this problem and if there is anything i can do to fix it.

---

<div class="post-metadata">

**Author:** ![tduva](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/tduva/32/392_2.png) [@tduva](https://discuss.dev.twitch.com/u/tduva)\
**Post date:** [October 15, 2016, 9:35pm UTC](https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809/2 "2016-10-15T21:35:47Z")

</div>

API endpoints are cached and you are probably getting different versions of the cache. You just can’t expect updates in realtime from it, so hitting more often than every minute or so might not make too much sense.

Hopefully at some point there will be a documented [PubSub](https://github.com/justintv/Twitch-API/tree/master/PubSub) topic for these kinds of things.

---

<div class="post-metadata">

**Author:** ![mateuszdrwal](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mateuszdrwal](https://discuss.dev.twitch.com/u/mateuszdrwal)\
**Post date:** [October 15, 2016, 9:49pm UTC](https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809/3 "2016-10-15T21:49:04Z")

</div>

i thought it had something to do with cacheing but i didnt know it could cache 2 different versions. thx for the response

---

<div class="post-metadata">

**Author:** ![martmists](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@martmists](https://discuss.dev.twitch.com/u/martmists)\
**Post date:** [October 16, 2016, 4:42pm UTC](https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809/4 "2016-10-16T16:42:16Z")

</div>

Just a note from another python user: please use snake\_case for functions as of [PEP 8](https://www.python.org/dev/peps/pep-0008/)

Good luck and have fun streaming!

---

<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:** [November 15, 2016, 4:42pm UTC](https://discuss.dev.twitch.com/t/the-api-output-bounces-alot/7809/5 "2016-11-15T16:42:19Z")

</div>

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