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 bero
Recipients bero
Date 2011-04-21.13:42:32
SpamBayes Score 1.3210752e-07
Marked as misclassified No
Message-id <1303393354.57.0.483160590848.issue11898@psf.upfronthosting.co.za>
In-reply-to
Content
Sending e.g. a JPEG file with a httplib POST request (e.g. through mechanize) can result in an error like this:

  File "/usr/lib64/python2.7/httplib.py", line 947, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 988, in _send_request
    self.endheaders(body)
  File "/usr/lib64/python2.7/httplib.py", line 941, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 802, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 2566: invalid start byte


The code triggering this is the attempt to merge the msg and message_body into a single request in httplib.py lines 791+

The patch I'm attaching treats an invalid string of unknown encoding (e.g. binary data wrapped as string) like something that isn't a string.

Works for me with the patch.
History
Date User Action Args
2011-04-21 13:42:34berosetrecipients: + bero
2011-04-21 13:42:34berosetmessageid: <1303393354.57.0.483160590848.issue11898@psf.upfronthosting.co.za>
2011-04-21 13:42:33berolinkissue11898 messages
2011-04-21 13:42:33berocreate