Specific example. There is a simple html form:

<form action="http://localhost:8000/submitPage" method="POST" enctype="multipart/form-data"> Login: <input name="Login" size="10"> <textarea name="Source" rows="20" style="width:560px"></textarea> <input type="SUBMIT" value="Отправить"> </form> 

And you need to parse the transmitted values ​​somehow. In numerous forums, people use cgi for such purposes:

 class MyHandler(BaseHTTPRequestHandler): def do_POST(s): ctype, pdict = cgi.parse_header(s.headers.get('content-type')) if ctype == 'multipart/form-data': s.body = cgi.parse_multipart(s.rfile, pdict) #problem here ... 

But going to parse_multipart everything hangs :(

  • Why enctype = "multipart / form-data" if only text is transmitted? Actually, only the Login and Source data come in, which are both plain / text. - Alex Silaev

2 answers 2

Outwardly it looks like everything is right. Surely some kind of bug. On the python, a whole bunch of bugs hangs about parse_multipart

    I would advise not to mess with naked CGI once again. Look in the direction of mod_python or its replacement mod_wsgi.

    And to make it even easier, use some kind of high-level framework like Django . Personally, when I need to process something simple, I am referring to Django. Everything is extremely simple and you don’t have to think about any nonsense - you only write the essence.

    Even if you feel that now it is you, sort of, do not - I assure you, it will come in handy in the future.