Dmitry Tsirkov <cyrko...@gmail.com> added the comment: I have recently stumbled upon this bug, and I can present the example and a solution I've used. The issue happens when we try to parse x-www-form-urlencoded of type bytes: ``` >>> from urllib.parse import urlencode, parse_qs >>> urlencode([('v', 'ö')]) 'v=%C3%B6' >>> parse_qs('v=%C3%B6') {'v': ['ö']} >>> parse_qs(b'v=%C3%B6') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.6/urllib/parse.py", line 669, in parse_qs encoding=encoding, errors=errors) File "/usr/lib64/python3.6/urllib/parse.py", line 722, in parse_qsl value = _coerce_result(value) File "/usr/lib64/python3.6/urllib/parse.py", line 103, in _encode_result return obj.encode(encoding, errors) UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 0: ordinal not in range(128) ``` This happens in the parse_qsl function because _coerce_result is a synonym of _encode_result and is called with default parameter encoding='ascii'. As far as I understand, it should be called with the encoding parameter of the parse_qsl function: ``` 742c742 < name = _coerce_result(name) --- > name = _coerce_result(name, encoding=encoding, errors=errors) 745c745 < value = _coerce_result(value) --- > value = _coerce_result(value, encoding=encoding, errors=errors) ``` I am not sure whether I should commit this to the repo and create a pull request, as described in the devguide.
---------- nosy: +cyrkov _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue30483> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com