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 Bob.Chen
Recipients Bob.Chen
Date 2014-08-20.02:49:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1408502977.94.0.555848371144.issue22231@psf.upfronthosting.co.za>
In-reply-to
Content
Try to run these two script below, and you will understand what I'm talking about.

If you specified an url and it happened to be an unicode string(which is quite common in python because python processes string as unicode and you could possibly get it from somewhere else), and your header contains a utf-8 string converted from a foreign language, like u'呵呵', then the codec error occurred.

File "/usr/lib/python2.7/httplib.py", line 808, in _send_output
    msg = "\r\n".join(self._buffer) 


# -*- encoding: utf-8 -*-
# should fail
import httplib, urllib
params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
headers = {"Content-type": "application/x-www-form-urlencoded",
        "Accept": "text/plain", 'notes': u'呵呵'.encode('utf-8')}
conn = httplib.HTTPConnection(u"bugs.python.org")
conn.request("POST", u"http://bugs.python.org/any_url", params, headers)
response = conn.getresponse()
print response.status, response.reason



# -*- encoding: utf-8 -*-
# should be ok
import httplib, urllib
params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
headers = {"Content-type": "application/x-www-form-urlencoded",
        "Accept": "text/plain", 'notes': u'呵呵'.encode('utf-8')}
conn = httplib.HTTPConnection(u"bugs.python.org")
conn.request("POST", "http://bugs.python.org/any_url", params, headers)
response = conn.getresponse()
print response.status, response.reason
History
Date User Action Args
2014-08-20 02:49:37Bob.Chensetrecipients: + Bob.Chen
2014-08-20 02:49:37Bob.Chensetmessageid: <1408502977.94.0.555848371144.issue22231@psf.upfronthosting.co.za>
2014-08-20 02:49:37Bob.Chenlinkissue22231 messages
2014-08-20 02:49:37Bob.Chencreate