[issue34226] cgi.parse_multipart() requires undocumented CONTENT-LENGTH in Python 3.7
New submission from Chih-Hsuan Yen <yan12125@gmail.com>: In Python 3.7, cgi.parse_multipart() requires "CONTENT-LENGTH" in the second parameter `pdict`. This is not necesary in Python 3.6. For example, the following code runs with 3.6: $ python3.6 Python 3.6.6 (default, Jun 27 2018, 13:11:40) [GCC 8.1.1 20180531] on linux Type "help", "copyright", "credits" or "license" for more information.
import cgi, io data = b'--heyDavid\r\nContent-Disposition: form-data; name="cfield"\r\n\r\njust a string\r\n\r\n--heyDavid--\r\n' cgi.parse_multipart(io.BytesIO(data), {"boundary": b"heyDavid"}) {'cfield': [b'just a string\r\n']}
While not on 3.7: $ python3.7 Python 3.7.0 (default, Jul 15 2018, 10:44:58) [GCC 8.1.1 20180531] on linux Type "help", "copyright", "credits" or "license" for more information.
import cgi, io data = b'--heyDavid\r\nContent-Disposition: form-data; name="cfield"\r\n\r\njust a string\r\n\r\n--heyDavid--\r\n' cgi.parse_multipart(io.BytesIO(data), {"boundary": b"heyDavid"}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.7/cgi.py", line 220, in parse_multipart headers['Content-Length'] = pdict['CONTENT-LENGTH'] KeyError: 'CONTENT-LENGTH'
I looked into the source code of CPython, and found CONTENT-LENGTH in nowhere but cgi.py and test_cgi.py. I guess it has the same meaning as the Content-Length header in HTTP or CONTENT_LENGTH environment variable in CGI? It would be great to document such a backward-incompatible behavior. Environment: Arch Linux with Python 3.6.6 from [extra] repo and 3.7.0 from [staging] repo. CC the author and the reviewer of issue29979, where relevant codes are introduced. ---------- assignee: docs@python components: Documentation, Library (Lib) messages: 322362 nosy: docs@python, orsenthil, quentel, yan12125 priority: normal severity: normal status: open title: cgi.parse_multipart() requires undocumented CONTENT-LENGTH in Python 3.7 type: behavior versions: Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by Karthikeyan Singaravelan <tir.karthi@gmail.com>: ---------- nosy: +xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
roger <rogerduran@gmail.com> added the comment: working on this on europython ---------- nosy: +rogerduran _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- keywords: +patch pull_requests: +8047 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by Tercio Gaudencio Filho <terciofilho@gmail.com>: ---------- nosy: +Tercio Gaudencio Filho _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by Fred L. Drake, Jr. <fdrake@gmail.com>: ---------- nosy: +fdrake _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by Niklas Sombert <niklas@ytvwld.de>: ---------- nosy: +ytvwld _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Martin Panter <vadmium+py@gmail.com> added the comment: Looks like the change causing this is revision cc3fa20. I would remove the reference to pdict['CONTENT-LENGTH']. ---------- keywords: +3.7regression nosy: +martin.panter _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Ned Deily <nad@python.org> added the comment: I note this is marked as a 3.7regression and still open. Since the cutoff for the final 3.7 bugfix mode release is in a few days, I'm assuming this means that 3.7 users will have to live with this regression. If you feel that is a problem, speak up now. ---------- nosy: +ned.deily _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Niklas Sombert <niklas@ytvwld.de> added the comment: Since there's the easy workaround of just setting pdict["CONTENT-LENGTH"] I personally don't have a problem with this staying the way it is. But it would be really nice if this were documented somewhere. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Senthil Kumaran <senthil@uthcode.com> added the comment: I will spend time on this on 12-June or 13-June, 2020. At the very least, if no changes are required, I will document this for 3.7 and higher versions. ---------- assignee: docs@python -> orsenthil _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset d8cf3514dd4682419a66f6e834bb384ee34afc95 by roger in branch 'master': bpo-34226: fix cgi.parse_multipart without content_length (GH-8530) https://github.com/python/cpython/commit/d8cf3514dd4682419a66f6e834bb384ee34... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +20073 pull_request: https://github.com/python/cpython/pull/20890 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +20074 pull_request: https://github.com/python/cpython/pull/20891 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +20075 pull_request: https://github.com/python/cpython/pull/20892 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset aa83935a56d1fd4d72d4de5f0278a240a2d6844d by Miss Islington (bot) in branch '3.7': [3.7] bpo-34226: fix cgi.parse_multipart without content_length (GH-8530) (GH-20892) https://github.com/python/cpython/commit/aa83935a56d1fd4d72d4de5f0278a240a2d... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset b87453f94fd391e6700eb25dd91de2e56aeeb98f by Miss Islington (bot) in branch '3.9': bpo-34226: fix cgi.parse_multipart without content_length (GH-8530) https://github.com/python/cpython/commit/b87453f94fd391e6700eb25dd91de2e56ae... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset c72b7f703eec45c1f4006bf5f65092daedaec46e by Miss Islington (bot) in branch '3.8': bpo-34226: fix cgi.parse_multipart without content_length (GH-8530) https://github.com/python/cpython/commit/c72b7f703eec45c1f4006bf5f65092daeda... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Change by Senthil Kumaran <senthil@uthcode.com>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.10, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
Senthil Kumaran <senthil@uthcode.com> added the comment: This is now fixed in all active versions of python. No documentation changes required for this change. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34226> _______________________________________
participants (11)
-
Chih-Hsuan Yen
-
Fred L. Drake, Jr.
-
Karthikeyan Singaravelan
-
Martin Panter
-
miss-islington
-
Ned Deily
-
Niklas Sombert
-
roger
-
Roundup Robot
-
Senthil Kumaran
-
Tercio Gaudencio Filho