1

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

类型错误:预期 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 -
4

0 回答 0