def encode(self, fields, files):
    body = io.BytesIO()
for chunk, chunk_len in self.iter(fields, files):
    body.write(chunk)
return self.content_type, body.getvalue()
Python standard library to POST multipart/form-data encoded data