title: Twitch TV API Call Generates Error 400 in GAE
body: <p>I've run into this issue in the past, and have been able to work around it until now. When making a call to the Twitch API in app engine, I get an Error 400. I've been to the google groups twitch page, as well as twitch tv's own forum.</p>
  
  <p>I was able to talk to a ton of people at Twitch TV as well as App Engine, and to no luck have I been able to solve this problem. In hopes of clarifying my question, I have been able to make a simple app to replicate directly what is occurring when I try to make a URL call to Twitch TV's API.</p>
  
  <p>Summary:</p>
  
  <p><strong>This is the simple code that fails when my application is deployed, but works flawlessly in the localhost environment:</strong></p>
  
  <pre><code>import webapp2
  import urllib2
  
  class MainHandler(webapp2.RequestHandler):
      def get(self):
      url = ('https://api.twitch.tv/kraken/streams/nl_kripp')
          contents = urllib2.urlopen(url)
      self.response.out.write(contents.read())
  
  
  app = webapp2.WSGIApplication([('/', MainHandler)],
                                debug=True)
  </code></pre>
  
  <p><strong>Here is what this exact application generates when being run on localhost (as it is suppose too):</strong></p>
  
  <p>{"stream":{"name":"live_user_nl_kripp","game":"Guild Wars 2","viewers":3229,"_links":{"self":"https://api.twitch.tv/kraken/streams/nl_kripp"},"_id":3681678672,"broadcaster":"fme","channel":{"game":"Guild Wars 2","name":"nl_kripp","created_at":"2012-04-15T02:25:31Z","teams":[{"name":"nolife","created_at":"2012-06-20T23:48:51Z","background":null,"updated_at":"2012-06-20T23:49:08Z","banner":null,"_links":{"self":"https://api.twitch.tv/kraken/teams/nolife"},"_id":330,"logo":null,"info":"\n","display_name":"noLife"}],"banner":null,"updated_at":"2012-08-26T21:12:55Z","background":"http://static-cdn.jtvnw.net/jtv_user_pictures/nl_kripp-channel_background_image-527e8b792a46df22.png","url":"http://www.twitch.tv/nl_kripp","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/nl_kripp-profile_image-267fd5e2fb95a15d-300x300.png","_id":29795919,"_links":{"stream_key":"https://api.twitch.tv/kraken/channels/nl_kripp/stream_key","self":"https://api.twitch.tv/kraken/channels/nl_kripp","chat":"https://api.twitch.tv/kraken/chat/nl_kripp","commercial":"https://api.twitch.tv/kraken/channels/nl_kripp/commercial","features":"https://api.twitch.tv/kraken/channels/nl_kripp/features"},"mature":null,"video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/nl_kripp-channel_offline_image-f3ad1124bc19cffd-640x360.png","display_name":"nl_Kripp","status":"nolife Kripparrian -- GW2 Ranger Lvling. Server = Maguuma"},"preview":"http://static-cdn.jtvnw.net/previews/live_user_nl_kripp-630x473.jpg","partner":true},"_links":{"self":"https://api.twitch.tv/kraken/streams/nl_kripp"}}</p>
  
  <p><strong>And now the same exact application in the App Engine environment:</strong></p>
  
  <p><a href="http://urltestingsite.appspot.com/" rel="nofollow">http://urltestingsite.appspot.com/</a></p>
  
  <p>I have spent quite a while trying to solve this problem as it is a major chain link in my website. Does anyone, have any remote idea as to why this occurs?</p>
  
  <p>EDIT - this is the code from my actual application:</p>
  
  <pre><code>def check_if_live(self, b):
      url = ('https://api.twitch.tv/kraken/streams/%s' %b)
      url2 = urlfetch.fetch(url, headers = {'User-Agent': "suitegamer_User-Agent"}) 
      contents = urllib2.urlopen(url2)
      if (contents.read()).find('{"stream":null,') == 0:
          return 'Offline'
      else:
          return 'Live'
  </code></pre>
  
  <p>This code is returning this AttributeError:</p>
  
  <pre><code>AttributeError: '_URLFetchResult' object has no attribute 'get_type'
  </code></pre>