python - 从 python 上的 curl 形成 request.post
问题描述
我有一个需要临时邮件的小项目,所以我找到了这个网站https://mail.tm/en,所以我试图通过 api 和此处给出的说明访问帖子https://api.mail.tm /。
由于我是使用 curl 等的新手,因此我在授权到那里的帐户时遇到了很多问题。
首先,我在网站上有一个 CURL 链接,如下所示:
curl -X POST "https://api.mail.tm/accounts" -H "accept: application/ld+json" -H "Authorization: testing" -H "Content-Type: application/ld+json" -d "{\"address\":\"test\",\"password\":\"stackoverflow\"}"
我试图在一个帖子请求中形成它,所以我这样做了
headers = {"accept": "application/ld+json", "Authorization": "header", "Content-Type": "application/ld+json"}
data = "{\"address\":\"zashyganii\",\"password\":\"chertila\"}"
mail = requests.post("https://api.mail.tm/accounts", data = data, headers = headers)
print(mail.status_code)
错误代码是 400,像这样在 api 网站上注明。
400 Error:
Response body
Download
{
"@context": "/contexts/ConstraintViolationList",
"@type": "ConstraintViolationList",
"hydra:title": "An error occurred",
"hydra:description": "address: This value is not a valid email address.\naddress: The domain \"\" is not valid.",
"violations": [
{
"propertyPath": "address",
"message": "This value is not a valid email address."
},
{
"propertyPath": "address",
"message": "The domain \"\" is not valid."
}
]
}
您能否将此 curl 转换为request.post
on python 以便它适用于此 api
解决方案
似乎请求没有任何问题。这是验证失败。
推荐阅读
- javascript - React componentDidMount 混淆
- python - Pandas 数据框中的变量运行总计
- c++ - 处理多个函数和参数
- java - 计算文件中数字平均值的程序(涉及尝试/捕获块)
- javascript - 车把:自定义 for 循环助手中的部分变量
- javascript - 使用 webpack 编译时来自 Terser 的 main.js 中的错误
- spring-boot - 关闭调试日志记录弹簧启动
- go - 重命名项目后不允许使用内部包 xxx
- python - Python:使用列表索引作为函数参数
- amazon-web-services - 在 AWS 中存储和执行大文本搜索