Page 1 of 1

CGI module deprecated Python 3.13

Posted: Fri Oct 10, 2025 12:01 pm
by Duggieb
I have a personal website http://robinboardman.me.uk, which I host on a Raspberry Pi 5 at home (uses apache). When I first wrote the site using PHP, I set up a guestbook which I have recently re-written in Python. This worked fine until I carried out a recent upgrade to Trixie which upgraded Python to version 3.13.
To handle the HTML form and the data via which visitors posted messages, I used the cgi module in Python and the FieldStorage method to extract and process the input data. However, the cgi module has been deprecated in Python 3.13 and hence my guestbook no longer works. I cannot find an obvious alternative in Python for the cgi.FieldStorage() method (cgi-legacy is mentioned but this seems a backward step). Does anyone have nay suggestions please?

Re: CGI module deprecated Python 3.13

Posted: Fri Oct 10, 2025 12:31 pm
by DeaD_EyE
https://docs.python.org/3.13/whatsnew/3 ... s-and-apis

cgi.FieldStorage can typically be replaced with urllib.parse.parse_qsl() for GET and HEAD requests, and the email.message module or the multipart library for POST and PUT requests.

Re: CGI module deprecated Python 3.13

Posted: Fri Oct 10, 2025 7:56 pm
by Duggieb
Thanks for that info. I shall look up and learn.

Re: CGI module deprecated Python 3.13

Posted: Mon Oct 13, 2025 7:57 am
by DeaD_EyE
If you don't want to change the code, then use this maybe: https://github.com/jackrosenthal/legacy-cgi

Re: CGI module deprecated Python 3.13

Posted: Mon Oct 13, 2025 1:53 pm
by Duggieb
Thanks for the reply but I am trying to just use Python 3.13 rather than legacy code.
I have decided to change the form method to GET and use os.environ.get('QUERY_STRING')

It will be obvious that I am a novice in Python. To further expand my Python abilities, I have followed example code to build a "bubble game" which I can run via Thonny and am using Python to run the Guestbook on my website. However, I feel progress is slow. Does anyone have any suggestions as to what path to follow to become more proficient in Python eg web courses, books to buy?

AltStyle によって変換されたページ (->オリジナル) /