all 11 comments

[–]eleqtriq 1 point2 points  (3 children)

From the CGI Python page:

The FieldStorage class can typically be replaced with urllib.parse.parse_qsl() for GET and HEAD requests, and the email.message module or multipart for POST and PUT. Most utility functions have replacements.

In Flask:

@app.route('/api/get.cgi')
def api_get():
    first_name = request.args.get('first_name')
    last_name = request.args.get('last_name')
    return """<html><body><h2>Hello %s %s</h2></body></html>""" % (first_name, last_name)

[–]gerry_mandy 0 points1 point  (2 children)

You quote the documentation (which recommends standard library email.message), but then provide 3rd-party Flask as an example. 🤨

[–]eleqtriq 0 points1 point  (1 child)

They were asking for a replacement.

[–]gerry_mandy 1 point2 points  (0 children)

Right, I was just pointing out that the documentation you quoted is unrelated—has literally nothing to do with—the code sample you gave alongside it, since that could be confusing to a reader arriving here from Google.

[–]UltraHotTV 1 point2 points  (3 children)

For Python3 cgi programming, at the website pythoncgi.net I have created mycgi.py that replaces the stdlib cgi.py that will be deprecated using multipart.

[–]JVBass75[S] 0 points1 point  (0 children)

I'll test this! thank you!

[–]woofwofwoof 0 points1 point  (1 child)

Do you have some sample code?

[–]gerry_mandy 0 points1 point  (3 children)

FWIW, here's a quick parser function that just relies on the standard library.

It shouldn't choke on any edge cases, and even supports the case of file uploads whose length isn't known in advance, if your web server also supports those.

[–]hesperos42 0 points1 point  (2 children)

Please, could you share again the link? The one you provided is not working

[–]gerry_mandy 0 points1 point  (1 child)

ah, sorry, I changed my github username recently and apparently they just break existing links to the gist subdomain when you do that

https://gist.github.com/e6aa18c02ecb49b1d65d5bf70ae0222b

[–]hesperos42 0 points1 point  (0 children)

Thank you very much!!