所以我有以下卷曲请求:
curl -F 'json={"method":"get_upload_status","params":{"token":"123","video_id":"456"}}' http://api.brightcove.com/services/post
期待回复
{"error": {"name":"InvalidTokenError","message":"invalid token","code":210}, "result": null, "id": null}
我试图将其转换为python请求,但是我发送它的服务器不断返回错误,它无法找到json。目前我正在尝试
import requests
data = {'params': {'token': '123', 'video_id':'456'}, 'method': 'get_upload_status'}
requests.post(url='http://api.thesite.com/services/post', json=data)
但它不断返回错误。我尝试过多种方法,包括
# 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))
基本上所有组合都无济于事。必须有一些简单的我做错了
答案 0 :(得分: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)