Repository navigation
Replace removed cgi module in main.py (Python 3.13) - #916
Open
kasparovabi wants to merge 1 commit into
Open
kasparovabi wants to merge 1 commit into
kasparovabi wants to merge 1 commit into
Conversation
cgi was removed from the standard library in Python 3.13 (PEP 594), so main.py stopped at import with ModuleNotFoundError. The Dockerfile base python:3-slim-bullseye resolves to 3.13, which makes 'make run' fail. The only use was cgi.escape(), which was already gone since 3.8. html.escape(..., quote=False) escapes the same three characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
main.pyimportscgiat the top. Python 3.13 removed that module (PEP 594, What's New in 3.13), and theDockerfilebase imagepython:3-slim-bullseyecurrently resolves to Python 3.13.6. Somake run(docker-compose,python main.py) andgunicorn main:appstop before Flask starts:The only use is
cgi.escape(tutorial_id)inget_tutorial().cgi.escapeitself was removed back in 3.8, so that line could not run on any supported version either.html.escape(s, quote=False)escapes the same three characters (&,<,>) and leaves quotes alone, which is whatcgi.escape(s)did by default. Onpython:3.7-slimthe two returned identical strings for four inputs, including<script>, quotes and an existing&.I loaded the app with Flask's test client in Docker with no network, requesting
/,/en/Hello,_World!,/en/Variables_and_Typesand/aboutwithHost: www.learnpython.org.python:3-slim-bullseye)ModuleNotFoundError: No module named 'cgi'The four response bodies after the change on 3.13 have the same SHA-256 as the unchanged code on 3.12. I did not run
tests/and did not try theideonecode runner, which needs credentials.Happy to adjust this or close it if it does not fit the project.