Skip to content

DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13 #437

Open

Description

@jugmac00
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

Also see:
https://peps.python.org/pep-0594/#cgi

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.

Activity

  1. mmerickel commented on May 29, 2022

    @mmerickel
    Member

    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.

  2. ondrejj commented on Oct 23, 2023

    @ondrejj

    Any update for this issue?

    Reported in red hat bugzilla:
    https://bugzilla.redhat.com/show_bug.cgi?id=2245641

  3. ztane commented on Dec 13, 2023

    @ztane

    The title could now be changed to "ImportError: no such module cgi" :'D

  4. ztane commented on Dec 13, 2023

    @ztane

    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.

  5. spiqueras commented on Jan 20, 2024

    @spiqueras

    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

  6. mgorny commented on May 18, 2024

    @mgorny

    Python 3.13.0b1 is out, and the cgi removal is "official" now.

  7. robtaylor commented on Oct 6, 2024

    @robtaylor

    any update on this?

  8. luhn commented on Oct 7, 2024

    @luhn
    Contributor

    I opened a PR to swap out cgi for the multipart package: #466

  9. mgorny commented on Oct 8, 2024

    @mgorny

    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#53 Kludex/python-multipart#152.

  10. robtaylor commented on Oct 8, 2024

    @robtaylor
  11. hynek commented on Oct 9, 2024

    @hynek

    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?

  12. defnull commented on Oct 11, 2024

    @defnull

    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#53 Kludex/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.

  13. frenzymadness commented on Oct 11, 2024

    @frenzymadness

    I'm just afraid that testing all possible combinations would make the testsuite complex.

  14. cjwatson commented on Nov 6, 2024

    @cjwatson

    The multipart vs. python-multipart situation should be resolved now (see pypa/packaging-problems#818).

  15. perseoGI commented on Feb 12, 2025

    @perseoGI

    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.

  16. mmerickel commented on Feb 14, 2025

    @mmerickel
    Member

    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.

  17. ml31415 commented on Mar 20, 2025

    @ml31415

    Nevertheless this deprecation warning is rather annoying and should be removed, if the issue is solved for recent python versions.

  18. defnull commented on Mar 27, 2025

    @defnull

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions