我正在 python 中使用 PayPal 发票,正如标题所示,我收到此错误。问题是,在 Postman 中,创建草稿发票罚款;在 python 中创建草稿发票是我遇到的唯一问题。我昨天这样做了,没有错误。
老实说,我认为这与数据有关,但我从这里复制了它(用于测试)(并更改了我需要更改的详细信息):https://developer.paypal.com/docs/开票/集成/#:~:text=%7B%0A%20%20%22detail%22%3A%20%7B,%7D%0A%20%20%7D%0A%7D
如果有帮助的话,回复号码是 400
import requests
import json
token="my token would be here"
link="https://api-m.sandbox.paypal.com/v2/invoicing/invoices"
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {token}"
}
with open("Json Files\draft.json","r") as file:
data=json.load(file)
response=requests.post(link,data=data,headers=headers)
print(response) #reponse 400
with open("Json Files\Result.json","w") as file:
json.dump(response.json(),file,indent=4)
{
"name": "INVALID_REQUEST",
"message": "Request is not well-formed, syntactically incorrect, or violates schema.",
"debug_id": "30d2ac87b6223",
"details": [],
"links": [
{
"href": "https://developer.paypal.com/docs/api/invoicing/#errors",
"method": "GET"
}
]
}
API 需要字符串,而不是字典
response=requests.post(link,data=json.dumps(data),headers=headers)