我要提出的问题是:How to create a job with Google Cloud scheduler Python api
我想知道如何插入要与函数一起传递的主体对象,我可以通过gcloud
来实现,并且根据v1文档,我知道主体需要在HttpTarget
中传递每当我尝试以这种方式传递它时,都会出错并说:
TypeError: No positional arguments allowed
老实说,我根本无法使from google.cloud.scheduler_v1.types import HttpTarget as Target
正常工作。
[有人可以给我一个例子,他们成功地使用API在Cloud Scheduler中创建了带有正文(JSON对象)的作业(当然是POST方法)吗?
import json
from google.cloud import scheduler_v1
client = scheduler_v1.CloudSchedulerClient()
project = "..." # TODO
location = "..." # TODO
parent = client.location_path(project, location)
uri = "..." # TODO
body = {"Hello": "World"}
job = {
"http_target": {
"http_method": "POST",
"uri": uri,
"headers": {"Content-Type": "application/json"},
"body": json.dumps(body).encode("utf-8"),
},
"schedule": "* * * * *",
}
response = client.create_job(parent, job)
print(response)