好吧,我放弃。我试图发布包含JSON的文件的内容。文件的内容如下所示:
{
"id”:99999999,
"orders":[
{
"ID”:8383838383,
"amount":0,
"slotID":36972026
},
{
"ID”:2929292929,
"amount":0,
"slotID":36972026
},
{
"ID”:4747474747,
"amount":0,
"slotID":36972026
}]
}
下面是可能有点离谱的代码:
#!/usr/bin/env python3
import requests
import json
files = {'file': open(‘example.json’, 'rb')}
headers = {'Authorization' : ‘(some auth code)’, 'Accept' : 'application/json', 'Content-Type' : 'application/json'}
r = requests.post('https://api.example.com/api/dir/v1/accounts/9999999/orders', files=files, headers=headers)
您需要解析JSON,然后像这样传递主体:
首先,json文件不包含有效的json。如中所示,
"id”
-这里的右引号不同于左引号。其他ID字段也有相同的错误。像这样"id"
。现在你可以这样做了
这应该行得通,但它是为非常大的文件准备的。
如果要发送较小的文件,请将其作为字符串发送。
相关问题 更多 >
编程相关推荐