Python请求:传递身份验证令牌

2024-04-26 22:34:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是MailJet的smsapi,在正确使用token/authentication语法时遇到了麻烦。在

在cURL中,请求应该如下所示(cfDocs):

curl -s \
     -X POST \
     --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
     https://api.mailjet.com/v4/sms-send \
     -H 'Content-Type: application/json' \
     -d '{
        "From": "MJPilot",
        "To": "+33600000000",
        "Text": "Have a nice SMS flight with Mailjet!"
      }'

但我不知道如何将这个短语转换成Python,这是我目前的想法:

^{pr2}$

作出如下回应:

SMS SENT{'ErrorIdentifier': 'f403ce05-1db3-4c30-ac74-314fa93a9e84', 'ErrorCode': 'mj-0002', 'ErrorMessage': 'Malformed JSON, please review the syntax and properties types.', 'StatusCode': 400}

我知道我的令牌是有效的,因为我可以通过邮递员正确地运行请求


Tags: tokenauthentication语法privatepubliccurlpostsms