[issue12327] in HTTPConnection the are len(body) and TypeError catch exception to detect if body is file like object, this hack do work with StringIO object

Martin Panter report at bugs.python.org
Mon Apr 13 09:06:18 CEST 2015


Martin Panter added the comment:

For the record, it looks like there were a few distinct but related problems here:

* Passing any StringIO object as the body is not supported (see <https://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.request>), because no StringIO class implements the fileno() method.

* Passing a Python 2 natively implemented StringIO.StringIO instance triggers the same AttributeError exception as in Issue 15267, incompatibility with TemporaryFile objects.

* Even if HTTPConnection.request() did support calculating Content-Length for StringIO objects, it would still be wrong for chunk-encoded bodies. I think the lower-level endheaders() or send() methods should be used instead. Or see Issue 12319, about adding chunked encoding for request().

----------
nosy: +vadmium

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12327>
_______________________________________


More information about the Python-bugs-list mailing list