1

I am experimenting with Google App Engine and have decided to use the Yelp API as my data source. In order to authenticate I need to some some keys and tokens to the Yelp server. The issue is on the response. I keep getting:

TypeError: expected httplib.Message, got

And I have no clue as to why. I am using the rauth library in addition to the Google App Engine.

Here is my code:

import webapp2

import rauth

from webapp2_extras import json


class Locations(webapp2.RequestHandler):

  def get(self):
    params = {}
    params["term"] = "restaurant"
    params["location"] = "Denver"
    params["limit"] = "10"

    consumer_key = "key here"
    consumer_secret = "secret here"
    token = "token here"
    token_secret = "secret here"

    session = rauth.OAuth1Session(
        consumer_key = consumer_key
        ,consumer_secret = consumer_secret
        ,access_token = token
        ,access_token_secret = token_secret)

    info = session.get("http://api.yelp.com/v2/search", params=params)

    self.response.write(json.encode(info))

app = webapp2.WSGIApplication([
('/locations', Locations),], debug=True)

Can anyone help me out here? I am expecting to receive some JSON here so I can send it to my Javascript.

Here is the full error I am getting in the terminal: Thanks in advance!

File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/Library/WebServer/Documents/helloworld/helloworld.py", line 23, in get
    info = session.get("http://api.yelp.com/v2/search", params=params)
  File "/Library/WebServer/Documents/helloworld/lib/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/rauth/session.py", line 210, in request
    return super(OAuth1Session, self).request(method, url, **req_kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/Library/WebServer/Documents/helloworld/lib/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "/Library/WebServer/Documents/helloworld/lib/requests/packages/urllib3/connectionpool.py", line 390, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/Library/WebServer/Documents/helloworld/lib/requests/packages/urllib3/util/response.py", line 48, in assert_header_parsing
    type(headers)))
TypeError: expected httplib.Message, got <type 'instance'>.
ERROR    2015-11-12 05:53:34,647 wsgi.py:279] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/Library/WebServer/Documents/helloworld/helloworld.py", line 23, in get
    info = session.get("http://api.yelp.com/v2/search", params=params)
  File "/Library/WebServer/Documents/helloworld/lib/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/rauth/session.py", line 210, in request
    return super(OAuth1Session, self).request(method, url, **req_kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/Library/WebServer/Documents/helloworld/lib/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/Library/WebServer/Documents/helloworld/lib/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "/Library/WebServer/Documents/helloworld/lib/requests/packages/urllib3/connectionpool.py", line 390, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/Library/WebServer/Documents/helloworld/lib/requests/packages/urllib3/util/response.py", line 48, in assert_header_parsing
    type(headers)))
TypeError: expected httplib.Message, got <type 'instance'>.
INFO     2015-11-12 05:53:34,653 module.py:794] default: "GET /locations HTTP/1.1" 500 -
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 2
    As covered towards the end of thread https://github.com/shazow/urllib3/issues/618 , urllib3/requests is currently broken for GAE -- the thread gives a diff you could patch in to fix it, or, previously in the thread, installing an older version of urllib3 is also said to help. – Alex Martelli Nov 13 '15 at 16:54

0 Answers0