Unit + wsgi.py + POST handler sample

Влад Крас vlad.kras at gmail.com
Mon Jan 22 12:01:52 UTC 2018


Try to update Unit to version 0.4 first

On Mon, Jan 22, 2018 at 2:56 PM Fedor Potapov <f.potapov18 at yandex.ru> wrote:

> Hello,
>
> I'm trying to learn nginx unit. GET queries work fine, thanks to examples.
> Nevertheless, when I try to process a POST, I get:
>
> --
> ERROR:root:The client disconnected while sending the body (12 more bytes
> were expected)
> Traceback (most recent call last):
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 1535, in
> __call__
>     rv = self.handle_exception(request, response, e)
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 1529, in
> __call__
>     rv = self.router.dispatch(request, response)
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 1278, in
> default_dispatcher
>     return route.handler_adapter(request, response)
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 1102, in
> __call__
>     return handler.dispatch()
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 572, in
> dispatch
>     return self.handle_exception(e, self.app.debug)
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 570, in
> dispatch
>     return method(*args, **kwargs)
>   File "/usr/local/www/unit/py/wsgi.py", line 24, in post
>     self.response.out.write(self.request.get('content'))
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 175, in
> get
>     param_value = self.get_all(argument_name)
>   File "/usr/local/lib/python2.7/site-packages/webapp2.py", line 212, in
> get_all
>     param_value = self.params.getall(argument_name)
>   File "/usr/local/lib/python2.7/site-packages/webob/request.py", line
> 851, in params
>     params = NestedMultiDict(self.GET, self.POST)
>   File "/usr/local/lib/python2.7/site-packages/webob/request.py", line
> 787, in POST
>     self.make_body_seekable()
>   File "/usr/local/lib/python2.7/site-packages/webob/request.py", line
> 941, in make_body_seekable
>     self.copy_body()
>   File "/usr/local/lib/python2.7/site-packages/webob/request.py", line
> 965, in copy_body
>     data = input.read(min(todo, 65535))
>   File "/usr/local/lib/python2.7/site-packages/webob/request.py", line
> 1557, in readinto
>     "(%d more bytes were expected)" % (self.remaining,)
> DisconnectionError: The client disconnected while sending the body (12
> more bytes were expected)
> --
>
>
> My sample code:
> --
> #!/usr/bin/env python
>
> import atexit, webapp2
>
> def cleanup():
>     print('Cleanup done.')
> atexit.register(cleanup)
>
> class Forms(webapp2.RequestHandler):
>     def get(self):
>         self.response.write("""
>          <html>
>             <body>
>               <form action="/sign" method="post">
>                 <div><textarea name="content" rows="3"
> cols="60"></textarea></div>
>                 <div><input type="submit" value="Sign"></div>
>               </form>
>             </body>
>           </html>""")
>
> class Sign(webapp2.RequestHandler):
>     def post(self):
>       self.response.out.write('<html><body>You wrote:<pre>')
>       self.response.out.write(self.request.get('content'))
>       self.response.out.write('</pre></body></html>')
>
> application = webapp2.WSGIApplication([
>     (r'/', Forms),
>     (r'/sign', Sign),
> ])
> --
>
> I'm assuming that the unitd drop connection before request.get and unitd
> does not know anything about the need to process POST here. How to
> correctly process POST here? Any timeout's ro read data upon POST ? Thank
> you.
>
> Env: Python 2.7, Unit-0.3, FreeBSD 11.1
>
> _______________________________________________
> unit mailing list
> unit at nginx.org
> https://mailman.nginx.org/mailman/listinfo/unit



-- 

С уважением,
Красовский Влад.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20180122/2d95ae4d/attachment.html>


More information about the unit mailing list