Frage

So trying I'm POSTing a compressed file via httplib2 in Python 3.2. I get the following error:

io.UnsupportedOperation: fileno

I used to post just an xml file but since those files are getting too big I want to compress them inside the memory first.

This is how I create the compressed file in memory:

contentfile = open(os.path.join(r'path', os.path.basename(fname)), 'rb')
tempfile = io.BytesIO()
compressedFile = gzip.GzipFile(fileobj=tempfile, mode='wb')
compressedFile.write(contentfile.read())
compressedFile.close()
tempfile.seek(0)

and this is how I'm trying to POST it.

http.request(self.URL,'POST', tempfile, headers={"Content-Type": "application/x-gzip", "Connection": "keep-alive"})

Any ideas ?

Like i said, it worked well when using the xml file i.e. contentfile

War es hilfreich?

Lösung

Solved by providing the "Content-Length" header which obviously removes the need for httplib2 to check the length.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top