Skip to content

Instantly share code, notes, and snippets.

@sigmavirus24
Last active December 25, 2015 13:39
Show Gist options
  • Save sigmavirus24/6985378 to your computer and use it in GitHub Desktop.
Save sigmavirus24/6985378 to your computer and use it in GitHub Desktop.
multipart/form-data in requests without files
from requests.packages.urllib3.filepost import encode_multipart_formdata
data = {
'form-field-0': 'value',
'form-field-1': 'value',
# ...
}
body, content_type_header = encode_multipart_formdata(fields=data)
r = requests.post(url, headers={'Content-Type': content_type_header}, data=body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment