1

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

1 Answer 1

1
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)
Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't seem to work. The server is now returning: {u'id': None, u'result': None, u'error': {u'message': u"A JSONObject text must begin with '{' at character 1 of params", u'code': 205, u'name': u'MalformedParametersError'}}
Seems that your back-end trying to parse value in json key, I've edited answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.