title: Bottle/Python - "IOError: [Errno 9] read() on write-only GzipFile object" when trying to decompress request body
body: <p>I use Bottle to receive gzipped request body. When the size of the request is small, everything is fine. However, if the size of request body is a bit larger (say, >= 20kb), an IOError is thrown.</p>
  
  <p>The following is the code used to read and decompress the request body:</p>
  
  <pre><code>@post("/receive")
  def receive():    
      try:
          f = request.body
          g_f = gzip.GzipFile(fileobj=f)
          content = g_f.read()
          # other stuff on the content...
      except IOError, e:  
          # handle the error
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code>[2015-09-07 16:27:27,967][ERROR   ] Failed to decompress gzipped data: [Errno 9] read() on write-only GzipFile object
  127.0.0.1 - - [07/Sep/2015 16:27:27] "POST /receive HTTP/1.1" 400 756
  </code></pre>