提问者:小点点

创建新应用程序API时出现DigitalOcean API错误。数码海洋。com/v2/apps


尝试在DigitalOcean上创建新的PaaS应用程序时出错。已经看过文档了,不知道为什么这不起作用。spec对象基本上取自docs。


import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer MY_TOKEN'
}

spec = {
    "name": "test-app",
    "region": "nyc1",
    "services": [
            {
                "name": "api",
                "github": {
                    "branch": "main",
                    "deploy_on_push": 'true',
                    "repo": "username/my-app"
                },
                "run_command": "python3 application.py",
                "environment_slug": "python",
                "instance_count": 2,
                "instance_size_slug": "basic-xxs",
                "routes": [
                    {
                        "path": "/api"
                    }
                ]
            }
    ]
}

payload = {'spec': spec}

res = requests.post(
    'https://api.digitalocean.com/v2/apps',
    headers=headers,
    data=payload,
)
print(res)
print(res.json())
print(res.status_code)


我得到以下错误。这是我发送数据的错误吗?

<Response [400]>
{'id': 'invalid_argument', 'message': "invalid character 's' looking for beginning of value"}


共2个答案

匿名用户

import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer MY_TOKEN'
}

spec = {
    "name": "test-app",
    "region": "nyc1",
    "services": [
            {
                "name": "api",
                "github": {
                    "branch": "main",
                    "deploy_on_push": 'True',
                    "repo": "username/my-app"
                },
                "run_command": "python3 application.py",
                "environment_slug": "python",
                "instance_count": 2,
                "instance_size_slug": "basic-xxs",
                "routes": [
                    {
                        "path": "/api"
                    }
                ]
            }
    ]
}

payload = {'spec': spec}

res = requests.post(
    'https://api.digitalocean.com/v2/apps',
    headers=headers,
    json=payload,
)
print(res)
print(res.json())
print(res.status_code)

匿名用户

尝试:

  1. json=payload(非data=payload
  2. deploy\u on\u push:True,Boolean(非字符串)