Bottle/Python – "IOError: [Errno 9] read() on write-only GzipFile object" when trying to decompress request body

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.

The following is the code used to read and decompress the request body:

def receive():    
        f = request.body
        g_f = gzip.GzipFile(fileobj=f)
        content =
        # other stuff on the content...
    except IOError, e:  
        # handle the error

The error message is:

[2015-09-07 16:27:27,967][ERROR   ] Failed to decompress gzipped data: [Errno 9] read() on write-only GzipFile object - - [07/Sep/2015 16:27:27] "POST /receive HTTP/1.1" 400 756

Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.