#!/usr/bin/python3 import python-multipart import sys import os fields = {} files = {} def on_field(field): fields[field.field_name] = field.value def on_file(file): files[file.field_name] = {'name': file.file_name, 'file_object': file.file_object} with open ("multipart", mode='rb') as file: form = file.read() multipart_headers = {'Content-Type': os.environ['CONTENT_TYPE']} multipart_headers['Content-Length'] = os.environ['CONTENT_LENGTH'] multipart.parse_form(multipart_headers, form, on_field, on_file) print(fields) print(files)