400 资源名称应以“/projects/<PROJECT_ID>/”开头

400 Resource name should start with "/projects/<PROJECT_ID>/"

当使用 Python 客户端 API 用于 Google Cloud Scheduler 时,出于某种原因我总是收到上述错误消息。我也尝试在没有斜杠的情况下启动父路径,但得到了相同的结果。 非常感谢任何提示!

import os
from google.cloud import scheduler_v1

def gcloudscheduler(data, context):
    current_folder = os.path.dirname(os.path.abspath(__file__))
    abs_auth_path = os.path.join(current_folder, 'auth.json')
    os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = abs_auth_path


    response = scheduler_v1.CloudSchedulerClient().create_job(data["parent"], data["job"])
    print(response)

我使用了以下参数:

{"job": {
        "pubsub_target": {
            "topic_name": "trade-tests",
            "attributes": {
                "attrKey": "attrValue"
            }
        },
        "schedule": "* * * * *"
    },
 "parent": "/projects/my-project-id/locations/europe-west1"
}

问题实际上不是 parent 参数而是 topic-name 的格式不正确。应该是projects/my-project-id/topics/trade-tests。即使错误消息说它应该带有斜杠。但它符合 API 文档 here and here.

问题只是错误消息没有说明错误与哪个资源名称有关。