“请求格式不正确、语法不正确或违反架构。”

问题描述 投票:0回答:1

我正在 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

创建草稿发票的Python代码

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)

Json结果数据数据


{
    "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"
        }
    ]
}

我预料到了这一点: https://developer.paypal.com/docs/invoicing/integrate/#:~:text=of%20the%20invoice.-,Step%20结果,W44B%2DKRGF%2DJM6R%2D26VU%22%2C%0A%20 %20%20%20%22方法%22%3A%20%22GET%22%0A%7D,-2.%20发送

python paypal paypal-sandbox invoice
1个回答
2
投票

API 需要字符串,而不是字典

response=requests.post(link,data=json.dumps(data),headers=headers)

© www.soinside.com 2019 - 2024. All rights reserved.