classification
Title: UnicodeEncode error in BaseHttpRequestHandler class when send unicode data.
Type: behavior Stage: patch review
Components: Unicode Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, jcarlosgalvezm, vstinner, wangyanfeng.p
Priority: normal Keywords: patch

Created on 2020-12-01 16:40 by wangyanfeng.p, last changed 2021-08-25 15:49 by jcarlosgalvezm.

Pull Requests
URL Status Linked Edit
PR 27948 open jcarlosgalvezm, 2021-08-25 15:22
Messages (1)
msg382268 - (view) Author: Yanfeng Wang (wangyanfeng.p) Date: 2020-12-01 16:40
My environment:
system: MacOS 10.15.x
python: 3.9.0

when I inherit the BaseHTTPRequestHandler class, and call the send_error(error_di, msg) method in my own class's do_GET override function:
the msg argument can't accept unicode string, an UnicodeEncodeError of 'latin-1' encoding error with ordinal call failed of out of range(255).

I tracked the code, and found in the implementation of this class, the data was sent through a encode call with 'latin-1' hard coded in. in the file: server.py near line 507. 
BTW, I tried u'my string'.encode('utf-8'), and it didn't work, another TypeError in module html __init__.py line 19.

If I commented the original hard code 'latin-1' line and replace with the hard code encoding to 'utf-8', all will be fine.
 
Thanks for your read anyone who cares or takes care of this issue.
History
Date User Action Args
2021-08-25 15:49:29jcarlosgalvezmsetversions: + Python 3.11
2021-08-25 15:48:58jcarlosgalvezmsetversions: + Python 3.8, Python 3.10
2021-08-25 15:22:11jcarlosgalvezmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request26395
2021-08-25 14:29:58jcarlosgalvezmsetnosy: + jcarlosgalvezm
2020-12-01 16:40:04wangyanfeng.pcreate