Title: urlencode produces bad output from ssl.CERT_NONE and friends that chokes decoders
Type: behavior Stage:
Components: Library (Lib), SSL Versions: Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: christian.heimes, ethan.furman, vitaly.krug
Priority: normal Keywords:

Created on 2018-03-08 06:57 by vitaly.krug, last changed 2018-07-11 07:53 by serhiy.storchaka.

Messages (2)
msg313424 - (view) Author: Vitaly Kruglikov (vitaly.krug) Date: 2018-03-08 06:57
In [9]: from urllib.parse import urlencode, parse_qs

In [10]: import ast, ssl

In [11]: d = dict(cert_reqs=ssl.CERT_NONE)

In [12]: urlencode(d)
Out[12]: 'cert_reqs=VerifyMode.CERT_NONE'

In [25]: parse_qs('cert_reqs=VerifyMode.CERT_NONE')
Out[25]: {'cert_reqs': ['VerifyMode.CERT_NONE']}
In [29]: ast.literal_eval('VerifyMode.CERT_NONE')
Traceback (most recent call last)
ValueError: malformed node or string: <_ast.Attribute object at 0x105c22358>

This used to work fine and produce `'cert_reqs=0'` on Python 2.7, allowing it to be decoded properly downstream. However, `'cert_reqs=VerifyMode.CERT_NONE'` can't be decoded generically. So, something it's that used to work in prior python versions that is breaking now.

Additional information. json.dumps() actually dumps that value as a number instead of 'VerifyMode.CERT_NONE'. 

It appears that urlencode doesn't work properly with enums, where I would expect it to emit the numeric value of the enum.
msg313732 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-03-13 08:58
Ethan, please take a look.
Date User Action Args
2018-07-11 07:53:35serhiy.storchakasettype: crash -> behavior
2018-03-13 08:58:05christian.heimessetassignee: ethan.furman

messages: + msg313732
nosy: + ethan.furman
2018-03-08 12:31:43christian.heimessetassignee: christian.heimes -> (no value)
2018-03-08 06:57:47vitaly.krugcreate