Python TypeError при получении ответа сервера

Я очень новичок во всем, что я делаю, поэтому, пожалуйста, держись со мной. Я экспериментирую с Google App Engine и решил использовать API Yelp в качестве источника данных. Для аутентификации мне нужно несколько ключей и токенов для сервера Yelp. Вопрос в ответе. Я продолжаю получать:

Ошибка типа: ожидается httplib.Message, получил

И я понятия не имею, почему. Я использую библиотеку rauth в дополнение к Google App Engine.

Вот мой код:

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 ответов

Другие вопросы по тегам