Tuesday, March 15, 2016

Post file issue of Python wsgiref simple_server

Leave a Comment

I'm writing a WSGI Python web server app with falcon framework. And I use wsgiref.simple_server for local test.

It works smoothly until I want to test posting a file to my server. My code is likes below:

  def on_post(self, req, resp):     """ handle files upload by user """      file_path = 'user_upload_file_' + str(uuid.uuid4())      with open(file_path, 'wb') as user_upload_file:          while True:             chunk = req.stream.read(4096)              if not chunk:                 break              user_upload_file.write(chunk)       # ... give back response ... 

Once I post with a file to my simple_server hosted app, it seems to hang on the line of req.stream.read().

But if I host my app with uWSGI, this piece of code works well.

Is this issue has something to do with simple_server?

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment