I try to post unicode data with the httplib.request
function:
s = u"עברית"
data = """
<spellrequest textalreadyclipped="0" ignoredups="1" ignoredigits="1" ignoreallcaps="0">
<text>%s</text>
</spellrequest>
""" % s
con = httplib.HTTPSConnection("www.google.com")
con.request("POST", "/tbproxy/spell?lang=he", data)
response = con.getresponse().read()
However this is my error:
Traceback (most recent call last):
File "C:\Scripts\iQuality\test.py", line 47, in <module>
print spellFix(u"╫á╫נ╫¿╫ץ╫ר╫ץ")
File "C:\Scripts\iQuality\test.py", line 26, in spellFix
con.request("POST", "/tbproxy/spell?lang=%s" % lang, data)
File "C:\Python27\lib\httplib.py", line 955, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 989, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 951, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 815, in _send_output
self.send(message_body)
File "C:\Python27\lib\httplib.py", line 787, in send
self.sock.sendall(data)
File "C:\Python27\lib\ssl.py", line 220, in sendall
v = self.send(data[count:])
File "C:\Python27\lib\ssl.py", line 189, in send
v = self._sslobj.write(data)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 97-102: or
dinal not in range(128)
Where am I wrong?