如何修复请求(urllib3)与app引擎一起工作?

时间:2016-03-14 20:54:36

标签: python google-app-engine python-requests urllib3

我使用请求库(或urllib3),试图从网站获取xml页面。我的代码工作正常,但是当我在app引擎中使用它时会显示错误

    Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\main.py", line 51, in get
    class_list = get_class_list()
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\get_class_urllib3.py", line 6, in get_class_list
    r = http.request('POST', 'http://sgo.volganet.ru/lacc.asp?Function=GetClassListForSchool&SchoolID=1460')
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\request.py", line 73, in request
    **urlopen_kw)
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\request.py", line 151, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\poolmanager.py", line 165, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\connectionpool.py", line 558, in urlopen
    body=body, headers=headers)
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\connectionpool.py", line 389, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\util\response.py", line 49, in assert_header_parsing
    type(headers)))

TypeError: expected httplib.Message, got <type 'instance'>.

那么你可以帮我修复这个问题,或者建议我可以在app angine中使用任何模块来创建不同站点的发布请求。

1 个答案:

答案 0 :(得分:0)

我建议使用AppEngine提供的API:urlfetch.fetch()