This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author harobed
Recipients harobed
Date 2011-06-13.17:50:08
SpamBayes Score 0.004151613
Marked as misclassified No
Message-id <1307987409.37.0.379147237937.issue12327@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

in httplib.HTTPConnection._send_request (Python 2.6)
in httplib.HTTPConnection._set_content_length (Python 2.7)
and http.client.HTTPConnection._set_content_length (Python 3.3)

there are something like that :

        try:
            thelen = str(len(body))
        except TypeError as te:
            # If this is a file-like object, try to
            # fstat its file descriptor
            try:
                thelen = str(os.fstat(body.fileno()).st_size)
            except (AttributeError, OSError):
                # Don't send a length if this failed
                if self.debuglevel > 0: print("Cannot stat!!")


If I put StringIO object in body and I do :

>>> len(body)
AttributeError: StringIO instance has no attribute '__len__'

I haven't TypeError.

I think we need to replace :

        try:
            thelen = str(len(body))
        except TypeError as te:

by :

        if hasattr(body, "read"):
           ... # it's file-like object
        else:
           ... # it's string object

What do you think about ?
History
Date User Action Args
2011-06-13 17:50:09harobedsetrecipients: + harobed
2011-06-13 17:50:09harobedsetmessageid: <1307987409.37.0.379147237937.issue12327@psf.upfronthosting.co.za>
2011-06-13 17:50:08harobedlinkissue12327 messages
2011-06-13 17:50:08harobedcreate