You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13 #437
git clone https://github.com/morepath/morepath
cd morepath
tox -e py311
...
.tox/py311/lib/python3.11/site-packages/webob/compat.py:5
/home/jugmac00/Projects/my-all-repos/output_zope/morepath/morepath/.tox/py311/lib/python3.11/site-packages/webob/compat.py:5: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
from cgi import parse_header
And yes I know - it will take a couple of years until anybody will use 3.14 :-)
Anyhow, seeing the same deprecation warnings with every test run is slightly annoying. If you are ok with the suggested replacement (see pep), I'd create a PR.
Reacted by Elephant Liu, Mike Fiedler, Éloi Rivard, Dave Brondsema, Preston Landers, Andrey Semakin, veenstrajelmer, Feanil Patel, James Roberts, Avasam and 11 more
webob has bigger problems with cgi than just the parse_header method but that being said I don’t see a big problem with the suggested fix. I would require a little due diligence to ensure that they are actually compatible apis.
Bitter rant: due diligence because the pep isn’t very trustworthy in its analyses from the perspective of the maintainer of a very popular library that’s apparently using a library so unpopular that it’s getting dropped from the stdlib.
Anyway, the cgi.py of 3.11 at least, contains ~1k lines in one file, of which ~700 lines are actually relevant, there is some unbelievable CGI html output garbage and some logging methods so I can understand why people want it gone, is it license-wise possible to vendor the 3.11 / 3.12 version into WebOb compat?
And with all due respect to Martijn for proposing those replacements; those replacement strategies are already in use in cgi.py as far as I can see and what remains... are those 700 lines of code.
For the record, multipart is not usable at the moment because two package authors claim the same package name, neither wants to give up, and packages randomly require one or the other: defnull/multipart#53Kludex/python-multipart#152.
FWIW there's also https://github.com/jackrosenthal/legacy-cgi which seems to be copy/paste of the CGI module. Conditionally depending on it might be the easier route to unblock 3.13 for the Pyramid ecosystem until the multipart situation is somehow resolved?
Reacted by Antti Haapala, Balazs Endresz and Michael
For the record, multipart is not usable at the moment because two package authors claim the same package name, neither wants to give up, and packages randomly require one or the other: defnull/multipart#53Kludex/python-multipart#152.
Some aspects that might help here:
The primary dependent of python-multipart is Starlette (FastAPI). There are others, but conflicts should be unlikely outside of Starlette/FastAPI projects. python-multipart is also optional and not a hard dependency for Starlette applications.
Depending on multipart does not cause issues for python-multipart users, only the other way around. Packages take priority over single-file modules during import.
Probably not the nicest solution, but it would be possible to depend on multipart and also vendor it, then detect conflicts at runtime and fall back on the vendored version if necessary and print a warning. This would not break any existing applications for anyone, and it would also not require this project to always keep the vendored version up to date as it is only used in rare conflict situations.
I think the only issue right now is that older versions of Python < 3.13 emit deprecation warnings because the stdlib cgi module has those warnings builtin. If you are using newer versions of Python >= 3.13 that use legacy-cgi there are no issues or warnings other than a complaint about using a dependency called legacy-cgi.
There is no easy way to avoid this deprecation message for WebOb with Python 3.11 or 3.12. Installing legacy-cgi for those Python versions would conflict with the actual cgi module. The only clean way would be to migrate away from cgi completely (e.g. to multipart).
Edit: I guess another way would be to wrap the import cgi in a with warnings.catch_warnings() to suppress it.
Edit 2: Or import webob.compat in your own app while suppressing warnings. No need to wait for webob to get rid of the warning for you.
Activity
mmerickel commentedon May 29, 2022
webob has bigger problems with cgi than just the parse_header method but that being said I don’t see a big problem with the suggested fix. I would require a little due diligence to ensure that they are actually compatible apis.
Bitter rant: due diligence because the pep isn’t very trustworthy in its analyses from the perspective of the maintainer of a very popular library that’s apparently using a library so unpopular that it’s getting dropped from the stdlib.
ondrejj commentedon Oct 23, 2023
Any update for this issue?
Reported in red hat bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=2245641
ztane commentedon Dec 13, 2023
The title could now be changed to "ImportError: no such module cgi" :'D
ztane commentedon Dec 13, 2023
Anyway, the
cgi.pyof 3.11 at least, contains ~1k lines in one file, of which ~700 lines are actually relevant, there is some unbelievable CGI html output garbage and some logging methods so I can understand why people want it gone, is it license-wise possible to vendor the 3.11 / 3.12 version into WebOb compat?And with all due respect to Martijn for proposing those replacements; those replacement strategies are already in use in
cgi.pyas far as I can see and what remains... are those 700 lines of code.spiqueras commentedon Jan 20, 2024
In case there's interest, I've tested installing the legacy-cgi package with Python 3.13.0a3 and all tests pass. Branch is here: https://github.com/spiqueras/webob/tree/py3.13
mgorny commentedon May 18, 2024
Python 3.13.0b1 is out, and the
cgiremoval is "official" now.robtaylor commentedon Oct 6, 2024
any update on this?
luhn commentedon Oct 7, 2024
I opened a PR to swap out
cgifor themultipartpackage: #466mgorny commentedon Oct 8, 2024
For the record,
multipartis not usable at the moment because two package authors claim the same package name, neither wants to give up, and packages randomly require one or the other: defnull/multipart#53 Kludex/python-multipart#152.robtaylor commentedon Oct 8, 2024
hynek commentedon Oct 9, 2024
FWIW there's also https://github.com/jackrosenthal/legacy-cgi which seems to be copy/paste of the CGI module. Conditionally depending on it might be the easier route to unblock 3.13 for the Pyramid ecosystem until the multipart situation is somehow resolved?
defnull commentedon Oct 11, 2024
Some aspects that might help here:
python-multipartis Starlette (FastAPI). There are others, but conflicts should be unlikely outside of Starlette/FastAPI projects.python-multipartis also optional and not a hard dependency for Starlette applications.multipartdoes not cause issues forpython-multipartusers, only the other way around. Packages take priority over single-file modules during import.Probably not the nicest solution, but it would be possible to depend on
multipartand also vendor it, then detect conflicts at runtime and fall back on the vendored version if necessary and print a warning. This would not break any existing applications for anyone, and it would also not require this project to always keep the vendored version up to date as it is only used in rare conflict situations.frenzymadness commentedon Oct 11, 2024
I'm just afraid that testing all possible combinations would make the testsuite complex.
cjwatson commentedon Nov 6, 2024
The
multipartvs.python-multipartsituation should be resolved now (see pypa/packaging-problems#818).perseoGI commentedon Feb 12, 2025
Hi there! This issue is still unresolved. Python 3.14 has been released, but the issue persists. Is there any progress or plans to address it?
I really appreciate any help you can provide.
mmerickel commentedon Feb 14, 2025
I think the only issue right now is that older versions of Python < 3.13 emit deprecation warnings because the stdlib cgi module has those warnings builtin. If you are using newer versions of Python >= 3.13 that use legacy-cgi there are no issues or warnings other than a complaint about using a dependency called legacy-cgi.
ml31415 commentedon Mar 20, 2025
Nevertheless this deprecation warning is rather annoying and should be removed, if the issue is solved for recent python versions.
defnull commentedon Mar 27, 2025
There is no easy way to avoid this deprecation message for WebOb with Python 3.11 or 3.12. Installing
legacy-cgifor those Python versions would conflict with the actualcgimodule. The only clean way would be to migrate away fromcgicompletely (e.g. to multipart).Edit: I guess another way would be to wrap the
import cgiin awith warnings.catch_warnings()to suppress it.Edit 2: Or
import webob.compatin your own app while suppressing warnings. No need to wait for webob to get rid of the warning for you.fix deprecation warning (relates to Pylons/webob#437)