Хочу получить переменные запроса POST
from sys import version as python_version
from cgi import parse_header, parse_multipart
if python_version.startswith('3'):
from urllib.parse import parse_qs
from http.server import BaseHTTPRequestHandler
else:
from urlparse import parse_qs
import BaseHTTPServer
import clementineDriver as Clementine
import web as Web
import functionality as Functionality
import config
#import os
class RequestHandler (BaseHTTPServer.BaseHTTPRequestHandler):
def do_POST (self):
ctype, pdict = parse_header(self.headers.getheader("content-type"))
action = '--'
if ctype == 'multipart/form-data':
postvars = parse_multipart(self.rfile, pdict)
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers.getheader('content-length'))
postvars = parse_qs(self.rfile.read(length), keep_blank_values=1)
else:
postvars = {}
self.sendHttpHeaders("text/html")
self.wfile.write(postvars)
return
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 47447)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
method()
File "/home/alex/.config/Clementine/wui/http.py", line 46, in do_POST
postvars = parse_multipart(self.rfile, pdict)
File "/usr/lib/python2.7/cgi.py", line 223, in parse_multipart
% (boundary,))
ValueError: Invalid boundary in multipart form: ''
----------------------------------------
Если запрос 'application/x-www-form-urlencoded' все нормально. Да.