Reputation: 751
curl 'https://example.com/v2/' -F '[email protected];type=image/JPEG' -H 'X-Generate-Renditions: all' -H 'X-Create-Asset-Sync: 1' -H 'Authorization: Bearer xyz' -H 'X-Read-Meta: none'
works without a hitch, but not the below python requests code returns 404.
import requests
headers = {
'X-Generate-Renditions': 'all',
'X-Create-Asset-Sync': '1',
'Authorization': 'Bearer xyz',
'X-Read-Meta': 'none'
}
with open('test.jpg', 'rb') as f:
response = requests.post('https://example.com/v2/', headers=headers, files={'test.jpg': f})
print(response.status_code)
Returns a 404.
What am I doing wrong?
Upvotes: 0
Views: 98
Reputation: 59209
You are not sending the file with the correct field name. Change the following part
files={'test.jpg': f}
to
files={'master': ('test.jpg', f, 'image/JPEG')}
See http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file for the correct usage.
Upvotes: 1