# Alternative function for deprecated cgi

**URL:** <https://discuss.python.org/t/alternative-function-for-deprecated-cgi/21960>\
**Category:** Python Help\
**Created:** [December 15, 2022, 8:31pm UTC](https://discuss.python.org/t/alternative-function-for-deprecated-cgi/21960 "2022-12-15T20:31:07Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![James\_E](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/james_e/32/12337_2.png) [@James\_E](https://discuss.python.org/u/James_E)\
**Post date:** [May 2, 2023, 9:41pm UTC](https://discuss.python.org/t/alternative-function-for-deprecated-cgi/21960/9 "2023-05-02T21:41:40Z")

</div>

> Terminating input is a whole other class of problem though, one that is hard to solve “completely” for CGI, WSGI, ASGI, or any other server spec. The `?a=b&c=d` syntax referenced in the original post is simple though, use `urllib.parse.parse_qs`.

The problem of input termination may be hard at a philosophical level (2 generals problem, protocol design, etc.), but it’s one that _was_ “solved” for many years with just `import cgi`.

Saying _to_ use `parse_qs` is one thing, but how one is actually to get the input _to_ that function out of a POST body reliably (which, again, is something we were able to do with no issue before 3.13) **is** the question—

> [@Pejamide](#):
>
> The GET part works fine. And POST part works well also, but with the deprecated function ‘cgi.fieldstorage’. I do not know how it can be replaced by function email or multipart, because I do not seen any possiblity there. Hence my [request for] help!

> [@smontanaro](#):
>
> Check the [`cgi` module docs](https://docs.python.org/3.11/library/cgi.html). It gives you alternatives right at the top.

I spent a few hours trying to go from the CGI module documentation’s vague exhortation “maybe you can use the `email` module somehow” to the multi-kilobyte shim I shared earlier. It took a lot of experimentation, a lot of creative labor, and I’m still not sure I did it right. If my code’s correct, I’d be happy to contribute a HOWTO page with a cleaned-up version of it to direct other CGI deprecatees to; but if (as I suspect) it’s totally doing it wrong, then I don’t see how an average person is supposed to interpret that suggestion of using the `email` module; maybe it should be removed?

---

_[View the full topic](https://discuss.python.org/t/alternative-function-for-deprecated-cgi/21960)._
