Message322362
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. |
|
Date |
User |
Action |
Args |
2018-07-25 14:55:40 | yan12125 | set | recipients:
+ yan12125, orsenthil, docs@python, quentel |
2018-07-25 14:55:40 | yan12125 | set | messageid: <1532530540.72.0.56676864532.issue34226@psf.upfronthosting.co.za> |
2018-07-25 14:55:40 | yan12125 | link | issue34226 messages |
2018-07-25 14:55:40 | yan12125 | create | |
|