Parsing Python HTML POST data from BaseHTTPServer

自闭症网瘾萝莉.ら 提交于 2019-12-07 16:28:44

问题


I'm sending a couple of files from an HTML form to my server which is based on BaseHTTPServer.

Within my do_POST I'm getting a string from rfile.read(length) which looks like some sort of multipart MIME string. Google is not being helpful on how I can decode this into something usable.

The output looks like this :

-----------------------------122422713313797828591978698502

Content-Disposition: form-data; name="MAX_FILE_SIZE"



1000000

-----------------------------122422713313797828591978698502

Content-Disposition: form-data; name="and_title_input"

and so on.

I've tried email.parser

from email.parser import Parser 
p=Parser()
msg=p.parsestr(s)

but msg doesn't seem to get me any nearer to my goal - it's not multipart and contains no payload.

I'm reduced to parsing the data myself - which is surely not the Pythonic way of doing things!

Have I missed something obvious? Has Google let me down? Can Stack Overflow save the day?


回答1:


Would cgi.parse_multipart meet your need? Also see a relevant discussion on comp.lang.python.



来源:https://stackoverflow.com/questions/3236597/parsing-python-html-post-data-from-basehttpserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!