Message225553
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 |
|
Date |
User |
Action |
Args |
2014-08-20 02:49:37 | Bob.Chen | set | recipients:
+ Bob.Chen |
2014-08-20 02:49:37 | Bob.Chen | set | messageid: <1408502977.94.0.555848371144.issue22231@psf.upfronthosting.co.za> |
2014-08-20 02:49:37 | Bob.Chen | link | issue22231 messages |
2014-08-20 02:49:37 | Bob.Chen | create | |
|