gpt4 book ai didi

python - 将Python REST API身份验证脚本转换为curl命令

转载 作者:行者123 更新时间:2023-12-01 05:16:21 35 4
gpt4 key购买 nike

我已经使用以下 python 脚本成功对 REST API 进行了身份验证:

import requests, base64
import json

VendorId = "a"
VendorPassword = "b"
UserId = "c"
UserPassword = "d"
PropertyId = "e"
authurl = "https://url/api/auth"
usrPass = '' + VendorId + ":" + VendorPassword

b64Val = base64.b64encode(usrPass)
payload = { "UserId" : UserId, "UserPassword" : UserPassword, "PropertyId" : PropertyId}
r = requests.post(authurl, headers = {"Authorization":b64Val}, data = payload)

我想通过curl来做到这一点(完全没有经验)。到目前为止我已经弄清楚的是:

curl -H "{'Authorization': 'abCdEfgHijKlmnop=='}" -X POST -v "https://url/api/auth" -d "batch={'PropertyId': 'e', 'UserId': 'c', 'UserPassword': 'd'}";

但我从 REST API 收到以下 502 错误...

如果我不使用 header ,则会出现以下错误:

< X-SERVICENAME-Auth-Error: Missing vendor credentials in HTTP auth header

我只是想了解我在这里缺少什么, header 语法是否错误,或者可能是curl参数放错了地方?

预先感谢您的任何想法/教程/建议!

最佳答案

您的 header 设置错误,它将是:

-H "Authorization: abCdEfgHijKlmnop=="

此外,如果您有授权用户:密码,那么您可以使用:

-u user:password

关于python - 将Python REST API身份验证脚本转换为curl命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23140447/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com