首页 > 解决方案 > 从 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.poston python 以便它适用于此 api

标签: pythonapi

解决方案


似乎请求没有任何问题。这是验证失败。


推荐阅读