You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File "E:\DEVELOP\python\lib\http\client.py", line 904, in _send_request
self.endheaders(body.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode character '\u7231' in
position 119: ordinal not in range(128)
I modified the lib/http/client.py document, and fix this problem.
I'm not sure what to do here. I guess changing to utf-8 is safe insofar
as the current code only accepts ascii, so the only code that breaks
will be code that depends on the encode() call raising an exception. It
seems like the client out to specify the encoding, though. We could fix
that via documentation.
jhylton commented on Mar 27, 2009
jhyltonmannequin
Mannequin
More actions
The documentation is pretty vague on this point. If you send something
other than plain ascii, it gets a bit tricky to figure out what other
headers need to be added. It would be safer for the client to pick an
encoding (e.g. utf-8) and encode the string before calling request().
It affects the content-length and presumably also the content-type.
jhylton commented on Mar 27, 2009
jhyltonmannequin
Mannequin
More actions
Ok. Discovered that RFC 2616 says that iso-8859-1 is the default
charset, so I will use that to encode strings instead of ascii. If you
want utf-8, you could encode the string yourself before calling
request(). Presumably, you should also add a content-type that explains
the charset. I'll clarified this in the docs.
Activity
cober commentedon Feb 19, 2009
Try to use http to send multi-byte utf8 data.
File "E:\DEVELOP\python\lib\http\client.py", line 904, in _send_request
self.endheaders(body.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode character '\u7231' in
position 119: ordinal not in range(128)
I modified the lib/http/client.py document, and fix this problem.
jhylton commentedon Mar 26, 2009
I'm not sure what to do here. I guess changing to utf-8 is safe insofar
as the current code only accepts ascii, so the only code that breaks
will be code that depends on the encode() call raising an exception. It
seems like the client out to specify the encoding, though. We could fix
that via documentation.
jhylton commentedon Mar 27, 2009
The documentation is pretty vague on this point. If you send something
other than plain ascii, it gets a bit tricky to figure out what other
headers need to be added. It would be safer for the client to pick an
encoding (e.g. utf-8) and encode the string before calling request().
It affects the content-length and presumably also the content-type.
jhylton commentedon Mar 27, 2009
Ok. Discovered that RFC 2616 says that iso-8859-1 is the default
charset, so I will use that to encode strings instead of ascii. If you
want utf-8, you could encode the string yourself before calling
request(). Presumably, you should also add a content-type that explains
the charset. I'll clarified this in the docs.
jhylton commentedon Mar 27, 2009
Committed revision 70638.