Search code examples
pythongoogle-app-enginepython-requestsurllib3

How to fix requests (urllib3) work with app engine?


I use requests library (or urllib3), trying to get xml page from web site. And my code is working, but when i use it in app engine it shows an error

    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'>.

So can you help me to fix this problem or suggest any module I can use in app angine to create post request to differen site.


Solution

  • I would recommend using the API provided by AppEngine: urlfetch.fetch()