This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cyrkov
Recipients cheryl.sabella, cyrkov, maxking
Date 2020-04-16.10:52:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587034321.36.0.194603584327.issue30483@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-04-16 10:52:01cyrkovsetrecipients: + cyrkov, maxking, cheryl.sabella
2020-04-16 10:52:01cyrkovsetmessageid: <1587034321.36.0.194603584327.issue30483@roundup.psfhosted.org>
2020-04-16 10:52:01cyrkovlinkissue30483 messages
2020-04-16 10:52:00cyrkovcreate