gpt4 book ai didi

python - API FedEx express "INVALID.INPUT.EXCEPTION","message":"Invalid field value in the input"

转载 作者:行者123 更新时间:2023-12-05 00:51:45 31 4
gpt4 key购买 nike

我正在尝试使用 Python 3.8 验证 FedEX API 中的地址,它返回无效字段值的错误

首先我连接到 Auth API

payload={"grant_type": "client_credentials",'client_id':Client_id,'client_secret':Client_secret}
url = "https://apis-sandbox.fedex.com/oauth/token"
headers = {'Content-Type': "application/x-www-form-urlencoded"}
response=requests.post(url, data=(payload), headers=headers)

它会正确返回带有 Auth token 的消息

{"access_token":"eyJhbGciOiJSUzI1NiIsInRM5U0F2eUs1ZVFBVTFzS5k","token_type":"bearer","expires_in":3599,"scope":"CXS SECURE"}

然后我只需获取 token 以在接下来的交易中使用它

token = json.loads(response.text)['access_token']

然后我为地址验证 API 准备下一个负载

payload_valid_address = {
"addressesToValidate": [
{
"address":
{
"streetLines": ["7372 PARKRIDGE BLVD"],
"city": "Irving",
"stateOrProvinceCode": "TX",
"postalCode": "75063-8659",
"countryCode": "US"
}
}
]
}

并使用给定的 token 将请求发送到新端点

url = "https://apis-sandbox.fedex.com/address/v1/addresses/resolve"
headers = {
'Content-Type': "application/json",
'X-locale': "en_US",
'Authorization': 'Bearer '+ token
}

response = requests.post(url, data=payload_valid_address, headers=headers)

print(response.text)

并得到错误

<Response [422]>
{"transactionId":"50eae03e-0fec-4ec7-b068-d5c456b64fe5","errors":[{"code":"INVALID.INPUT.EXCEPTION","message":"Invalid field value in the input"}]}

我进行了无数次测试,但没有得到无效字段。有谁知道发生了什么并可以提供帮助?

最佳答案

payload = json.dumps({input payload}) 这可以防止响应错误 422<响应 [422]>

关于python - API FedEx express "INVALID.INPUT.EXCEPTION","message":"Invalid field value in the input",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71228838/

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