我正试图通过下面提到的函数修补(更新(云调度程序中的一个作业。此函数使用api来更新作业的属性(access_token(。然而,它没有正确部署。代码中有问题吗?
导入base64从pprint导入pprint
来自googleapiclient导入发现从oauth2client.client导入GoogleCredentials
def hello_subsub(事件,上下文(:
credentials = GoogleCredentials.get_application_default()
service = discovery.build('cloudscheduler', 'v1', credentials=credentials)
name = 'projects/XYZ/locations/TempLocation/jobs/TestTopic'
job_body = {
"name": "temp",
"description": temp,
"pubsubTarget": {
"topicName": "projects/XYZ/topics/TestTopic",
"attributes": {
"access_token": "blabla"
}
},
"httpTarget": {
"uri": "https://cloudscheduler.googleapis.com/v1/projects/XYZ/locations/TempLocation/jobs/TestTopic",
"httpMethod": "POST",
"headers": {
"Content-Type": "application/json",
},
"oauthToken": {
"serviceAccountEmail": "xyz@gmail.com",
}
}
}
request = service.projects().locations().jobs().patch(name=name, body=job_body)
response = request.execute()
pprint(response)
如@Akshansha Singhal所述,请参阅此处。
对于";googleapiclient";,最新的默认版本2.0仅在Python 3.6+上受支持。
如果在Python 2.7+上,请使用1.x.版本
您可以在您的";requirements.txt";。