Twitch API is Generating an Error 400 in App Engine

107 views
Skip to first unread message

suite...@gmail.com

unread,
Aug 26, 2012, 4:49:26 PM8/26/12
to justintv-ap...@googlegroups.com
Hello hello.

I seem to be getting an error 400 whenever I try to pass the twitch tv api within my application. My application works fine on localhost but fails when deployed.

I was sent here by the twitch tv moderators.

Here is my post on the twitch forums with all the information:

support.twitch.tv/discussion/6124/twitch-api-is-generating-an-error-in-app-engine

Could somebody please help me!

Mike Ossareh

unread,
Aug 26, 2012, 8:08:19 PM8/26/12
to justintv-ap...@googlegroups.com
Hi, 

Please use the Twitch Streams API, part of the new Twitch API. Let us know if you still have issues once you've moved over.


--
You received this message because you are subscribed to the Google Groups "Justin.tv API Developers" group.
To post to this group, send email to justintv-ap...@googlegroups.com.
To unsubscribe from this group, send email to justintv-api-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/justintv-api-developers/-/blPIjfa1ch0J.
For more options, visit https://groups.google.com/groups/opt_out.



suite...@gmail.com

unread,
Aug 26, 2012, 8:39:36 PM8/26/12
to justintv-ap...@googlegroups.com
I implemented it into my function as such to check if the stream is live:

def check_if_live(self, b):
url = ('https://api.twitch.tv/kraken/streams/%s' %b)
contents = urllib2.urlopen(url)
if (contents.read()).find('{"stream":null,') == 0:
return 'Offline'
else:
return 'Live'

I am receiving the same error.

Mike Ossareh

unread,
Aug 26, 2012, 8:48:05 PM8/26/12
to justintv-ap...@googlegroups.com
What value does b have at this point?
 

I am receiving the same error.
--
You received this message because you are subscribed to the Google Groups "Justin.tv API Developers" group.
To post to this group, send email to justintv-ap...@googlegroups.com.
To unsubscribe from this group, send email to justintv-api-deve...@googlegroups.com.

suite...@gmail.com

unread,
Aug 26, 2012, 8:49:21 PM8/26/12
to justintv-ap...@googlegroups.com
b is the stream name. For instance, http://www.twitch.tv/onemoregametv - b = onemoregametv

Mike Ossareh

unread,
Aug 26, 2012, 8:59:13 PM8/26/12
to justintv-ap...@googlegroups.com
Hi, yes I know - I'm a programmer and can read your code without issue :)

I'm asking - what is b's value when you get the 400. Using your example I get a non-400 response for onemoregametv: https://api.twitch.tv/kraken/streams/onemoregametv 

Also... you may want to use a JSON lib instead of doing the string match you're doing right now. As is I wouldn't be shocked to find out the exception is not coming from the API call, but rather from how you're handling the response.
 

--
You received this message because you are subscribed to the Google Groups "Justin.tv API Developers" group.
To post to this group, send email to justintv-ap...@googlegroups.com.
To unsubscribe from this group, send email to justintv-api-deve...@googlegroups.com.

suite...@gmail.com

unread,
Aug 26, 2012, 9:08:05 PM8/26/12
to justintv-ap...@googlegroups.com
It most likely is how i'm handling it. I'm relatively new to programming, so I tried to find a way to figure out if a stream is live via python. The app works so awesomely on localhost but dies when its deployed. I haven't a clue how to do it in json, but i'll do some reading I suppose.

How would I figure out what b value is passed? I can't see the source code. Excuse my lack of know how...

Mike Ossareh

unread,
Aug 26, 2012, 9:13:28 PM8/26/12
to justintv-ap...@googlegroups.com
If it works locally and not when deployed then it suggests that something is different about the deployed environment. I googled along those lines and found this: https://groups.google.com/forum/#!topic/google-appengine-go/Z6hp_gLSfKs

I don't think that is necessarily applicable to you though. You may want to work out how to see logs on your GAE instance: https://developers.google.com/appengine/articles/logging
 

--
You received this message because you are subscribed to the Google Groups "Justin.tv API Developers" group.
To post to this group, send email to justintv-ap...@googlegroups.com.
To unsubscribe from this group, send email to justintv-api-deve...@googlegroups.com.

suite...@gmail.com

unread,
Aug 26, 2012, 9:30:30 PM8/26/12
to justintv-ap...@googlegroups.com
I can see the logs of the GAE instance, but they don't show much.

I posted the errors in the twitch thread I made here:

support.twitch.tv/discussion/6124/twitch-api-is-generating-an-error-in-app-engine

I may have to do this in json as you suggested.

Mike Ossareh

unread,
Aug 26, 2012, 9:36:53 PM8/26/12
to justintv-ap...@googlegroups.com
I don't think JSON will suddenly make this work. 400 means you're asking for something that doesn't work. Without seeing all your code then it is hard to speculate as to what is going on, but looking at this stack trace I do see something suspicious:

File "/base/data/home/apps/s~suitegamer/1.361316860569454472/main.py", line 457, in get
    check_if_life2 = self.check_if_live((streamss[(streamss.find('.tv/')+ 4):]))
 

the argument to streamss.find looks like it is not a complete URL? It is directly after this that you're getting your exception thrown - so I suggest you start from there.


--
You received this message because you are subscribed to the Google Groups "Justin.tv API Developers" group.
To post to this group, send email to justintv-ap...@googlegroups.com.
To unsubscribe from this group, send email to justintv-api-deve...@googlegroups.com.

suite...@gmail.com

unread,
Aug 26, 2012, 9:44:40 PM8/26/12
to justintv-ap...@googlegroups.com
Yes, that little tidbit of code was from development. It is now gone. Ill work something out I suppose eventually. Thanks for the info :)

suite...@gmail.com

unread,
Aug 26, 2012, 9:46:00 PM8/26/12
to justintv-ap...@googlegroups.com, suite...@gmail.com
Do you mind if I ask if there any authentication/cookie creation going on here?

doubl...@gmail.com

unread,
Aug 26, 2012, 10:34:10 PM8/26/12
to justintv-ap...@googlegroups.com, suite...@gmail.com
On this post[1], you are using http instead of https. This will cause 400s if that's the request you're making from App Engine.

[1]: http://support.twitch.tv/discussion/comment/23882/#Comment_23882

suite...@gmail.com

unread,
Aug 26, 2012, 10:41:57 PM8/26/12
to justintv-ap...@googlegroups.com, suite...@gmail.com, doubl...@gmail.com
This is my fucntion now, its still generating error 400.

def check_if_live(self, b):
url = ('https://api.twitch.tv/kraken/streams/%s' %b)
contents = urllib2.urlopen(url)
if (contents.read()).find('{"stream":null,') == 0:
return 'Offline'
else:
return 'Live'

I may have to find another way to do this...I've tried quite a few things here...

suite...@gmail.com

unread,
Aug 27, 2012, 4:55:40 PM8/27/12
to justintv-ap...@googlegroups.com, suite...@gmail.com, doubl...@gmail.com
Ok, i've managed to get past this issue using this function:

def check_if_live(self, b):
url = ('https://api.twitch.tv/kraken/streams/%s' %b)
result = urlfetch.fetch(url, headers = {'User-Agent': "suitegamer"})
check = result.content
if (check).find('{"stream":null,') == 0:
return 'Offline'
else:
return 'Live'

For now, the only remaining problem is that when deployed, the call returns no data at all. Again, it works perfectly on localhost.

suite...@gmail.com

unread,
Aug 27, 2012, 5:27:54 PM8/27/12
to justintv-ap...@googlegroups.com, suite...@gmail.com, doubl...@gmail.com
The user-agent from app engine apps always appends AppEngine-Google to the end of any user-agent you specify. From what I understood, the punctuation of { ; : . - } would cause the request to not be answered by the twitch api. The dash in the middle of AppEngine-Google is probably what is causing a failure here. That would also mean that every google app engine app is isolated from contacting the twitch api!

If this is the case, I can't do anything to fix it on my end...

Mike Ossareh

unread,
Aug 27, 2012, 5:52:43 PM8/27/12
to justintv-ap...@googlegroups.com
Hey Suitegamer, 

I had to start a new thread because however it is that you're replying to emails breaks my browser.

The user-agent from app engine apps always appends AppEngine-Google to the end of any user-agent you specify. From what I understood, the punctuation of { ; : . - } would cause the request to not be answered by the twitch api. The dash in the middle of AppEngine-Google is probably what is causing a failure here. That would also mean that every google app engine app is isolated from contacting the twitch api!

Ah, yes, you are right - the benefits of having an email archive! I'd investigated this some amount a while ago but didn't pursue it through to a fix. I'll look into this again in the near future and let you know where I get.

Fire

unread,
Aug 27, 2012, 6:44:48 PM8/27/12
to justintv-ap...@googlegroups.com
He also has a thread about this on the forums, we tested the useragents theory with curl and can't confirm it


Mike Ossareh

unread,
Aug 27, 2012, 7:05:34 PM8/27/12
to justintv-ap...@googlegroups.com
On Mon, Aug 27, 2012 at 3:44 PM, Fire <dragon...@gmail.com> wrote:
He also has a thread about this on the forums, we tested the useragents theory with curl and can't confirm it

I have confirmed this in the past. I'll let you know what I find.
 


http://pastie.org/private/nymiyxhkwm6ku1symah1bg


On Monday, August 27, 2012 5:52:44 PM UTC-4, Mike Ossareh wrote:
Hey Suitegamer, 

I had to start a new thread because however it is that you're replying to emails breaks my browser.

The user-agent from app engine apps always appends AppEngine-Google to the end of any user-agent you specify. From what I understood, the punctuation of { ; : . - } would cause the request to not be answered by the twitch api. The dash in the middle of AppEngine-Google is probably what is causing a failure here. That would also mean that every google app engine app is isolated from contacting the twitch api!

Ah, yes, you are right - the benefits of having an email archive! I'd investigated this some amount a while ago but didn't pursue it through to a fix. I'll look into this again in the near future and let you know where I get.

--
You received this message because you are subscribed to the Google Groups "Justin.tv API Developers" group.
To post to this group, send email to justintv-ap...@googlegroups.com.

To unsubscribe from this group, send email to justintv-api-deve...@googlegroups.com.

suite...@gmail.com

unread,
Aug 28, 2012, 1:56:06 PM8/28/12
to justintv-ap...@googlegroups.com
Does this possibly have to do with the IP Address limit? If twitch is limited to 180 calls / hour from a specific IP address, well then I'm assuming that the call doesn't go through as that limit is reached.

Of course its not reached on my local pc, but there are MANY apps served on app engine that i'm sure use twitch and i'm sure share the same IP. If so, any fixes for this?
Reply all
Reply to author
Forward
0 new messages