python - 如何将python dict变成Curl
问题描述
由于某些原因,我对 API 的请求失败了。这是代码:
def create_alert(alert_dict)
url = host + '/api/alerts'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer tokengen'
}
response = requests.request('POST', url, headers = headers, data=json.dumps(alert_dict))
return response
alert_dict = {
"priority": "1",
"to": to,
"from": from_
}
response = create_alert(alert_dict)
print(response)
我这样做的方式是将所有内容保存到字典中,然后用它发出 POST 请求。但由于某种原因,我收到了 500 错误。
这是正在工作的卷曲
curl --location --request POST "http://newhost.com/api/alerts" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer tokengen" \
--data "{
\"to\": \"sample@email.com\",
\"from\": \"from@email.com\",
\"priority\": \"1\",
}"
--data
我应该如何将我的 dict 转换为在请求时可以像 curl 一样工作
解决方案
推荐阅读
- wolfram-mathematica - 绘制它的最佳方法
- arrays - 数组的副本正在改变原始
- c# - 通过扩展方法进行模板特化
- ruby - 导出的资源不适用于 puppet
- c++ - std::istream& 运算符>>(std::istream& , ClassName& )
- php - 匿名存储电子邮件地址
- facebook-messenger-bot - Facebook Messenger Bot - 将控制权从机器人传递给人类并启用键盘输入
- python - Flask 和 Certbot
- java - 二叉搜索树搜索疑难解答
- java - NetBeans 电子商务教程提交订单错误