I'm trying to upload an image to Sirv through python requests. Here is what I have so far;
def upload_files(access_token, filename):
endpoint = "https://api.sirv.com/v2/files/upload"
headers = {'Content-Type' : 'application/json', 'authorization': 'bearer {}'.format(access_token)}
send_request = requests.post(endpoint, headers = headers, data = filename)
return send_request
access_token = "MY_ACCESS_TOKEN"
filename = {'filename': ('oldman.jpg', open('oldman.jpg', 'rb'))}
upload_files(access_token, filename)
I understand http status codes. However, I fail to understand what I'm doing wrong to get a 400 thrown by the server. Here's the full response I'm getting;
{'_content': b'{\n "statusCode": 400,\n "error": "Bad Request",\n "message": "child 'filename' fails because ['filename' is required]"\n}', '_content_consumed': True, '_next': None, 'status_code': 400, 'headers': {'Date': 'Fri, 26 Jun 2020 13:41:02 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '121', 'Connection': 'keep-alive', 'access-control-allow-origin': '', 'access-control-expose-headers': '', 'cache-control': 'no-cache', 'Server': 'Sirv.API'}, 'raw': <urllib3.response.HTTPResponse object at 0x7f51f39c80a0>, 'url': 'https://api.sirv.com/v2/files/upload', 'encoding': 'utf-8', 'history': [], 'reason': 'Bad Request', 'cookies': <RequestsCookieJar[]>, 'elapsed': datetime.timedelta(seconds=7, microseconds=408883), 'request': <PreparedRequest [POST]>, 'connection': <requests.adapters.HTTPAdapter object at 0x7f51f44422b0>}
From the error, I suspect that the server is somehow not detecting my filename parameter. I am using this doc as a guide to querying the API.
Summary: I need help understanding why I'm getting the error.