Skip to content

Instantly share code, notes, and snippets.

@mraarif
Created October 26, 2018 12:15
Show Gist options
  • Save mraarif/d54fa746cf8ca457d79dcdda3c30f84d to your computer and use it in GitHub Desktop.
Save mraarif/d54fa746cf8ca457d79dcdda3c30f84d to your computer and use it in GitHub Desktop.
python How to upload file, multipart Post request
import requests
def post_multipart():
try:
user = {'email': 'testuser@example.com', 'first_name': 'test user 1','password': 'samplepassword'}
image = {'image': open('path/to/file', 'rb')}
requests.post('/api/url', files=image, data=user)
except Exception as ex:
print('user creation failed')
print(str(ex))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment