0

尝试在 DigitalOcean 上创建新的 PaaS 应用程序时出错。已经看过文档并且无法弄清楚为什么这不起作用。该spec对象基本上取自文档。


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

4

2 回答 2

0

尝试:

  1. json=payload(不是data=payload
  2. deploy_on_push": True,布尔值(不是字符串)
于 2021-12-20T17:39:21.100 回答
0
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)
于 2021-12-20T17:47:28.817 回答