接收服务器响应时的Python TypeError

时间:2015-11-12 05:58:12

标签: python google-app-engine rauth

我正在尝试使用Google App Engine,并决定使用Yelp API作为我的数据源。为了进行身份验证,我需要一些密钥和令牌到Yelp服务器。问题在于回应。我一直在说:

TypeError:期望的httplib.Message,得到

我不知道为什么。除Google App Engine外,我还在使用rauth库。

这是我的代码:

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)

任何人都可以帮助我吗?我期待在这里收到一些JSON,所以我可以将它发送到我的Javascript。

以下是我在终端中收到的完整错误:提前致谢!

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 -

0 个答案:

没有答案