1from requests_toolbelt import MultipartEncoder
2import requests
3
4m = MultipartEncoder(
5 fields={'field0': 'value', 'field1': 'value',
6 'field2': ('filename', open('file.py', 'rb'), 'text/plain')}
7 )
8
9r = requests.post('http://httpbin.org/post', data=m,
10 headers={'Content-Type': m.content_type})
11