Reputation: 1299
So I have the following curl request:
curl -F 'json={"method":"get_upload_status","params":{"token":"123","video_id":"456"}}' http://api.brightcove.com/services/post
And expect the response
{"error": {"name":"InvalidTokenError","message":"invalid token","code":210}, "result": null, "id": null}
And I'm trying to convert it to a python request, but the server I'm sending it to keeps returning an error that it can't find the json. Currently I'm trying
import requests
data = {'params': {'token': '123', 'video_id':'456'}, 'method': 'get_upload_status'}
requests.post(url='http://api.thesite.com/services/post', json=data)
But it keeps returning an error. I've tried multiple things including
# Attempt 1
requests.post(url='http://api.brightcove.com/services/post', data=data)
# Attempt 2
import json
requests.post(url='http://api.brightcove.com/services/post', data=json.dumps(data))
# Attempt 3
import json
requests.post(url='http://api.brightcove.com/services/post', json=json.dumps(data))
And basically all combinations of that all to no avail. There has to be something simply I'm doing wrong
Upvotes: 1
Views: 147
Reputation: 10135
import requests
import json
data = {'json': json.dumps({'params': {'token': '123', 'video_id':'456'}, 'method': 'get_upload_status'})}
requests.post(url='http://api.thesite.com/services/post', data=data)
Upvotes: 1