我尝试使用 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)
它会正确返回一 strip 有身份验证 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/