简体   繁体   English

尝试访问 Cloud Composer API

[英]Trying to access Cloud composer APIs

I am using below code to modify Airflow dag status.我正在使用以下代码修改 Airflow dag 状态。

statusObject = {"state": "failed"}
AUTH_SCOPE = "https://www.googleapis.com/auth/cloud-platform"
CREDENTIALS, _ = google.auth.default(scopes=[AUTH_SCOPE])
authed_session = AuthorizedSession(CREDENTIALS)
headers = {'content-type': 'application/json', 'accept': 'application/json'}

url = "https://{composer-name}.composer.googleusercontent.com/api/v1/dags/" + dag_run.conf["dag_id"] + "/dagRuns/" + dag_run.conf["cancel_dag_id"]

response= authed_session.request("PATCH", url, json=statusObject,headers=headers)

I am getting 401 unauthorised because the service account I am using has access_type = 'online' .我收到401 unauthorised ,因为我使用的服务帐户具有access_type = 'online'

How can I make this API request or set access_type='offline' programmatically?如何以编程方式发出此 API 请求或设置access_type='offline'

@Abhishek Singh, As you have mentioned in the comment, issue can be resolved by limiting the character size of service account ID. @Abhishek Singh,正如您在评论中提到的,可以通过限制服务帐户 ID 的字符大小来解决问题。

The ID must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. ID 必须介于 6 到 30 个字符之间,并且可以包含小写字母数字字符和破折号。 After you create a service account, you cannot change its name.创建服务帐户后,您无法更改其名称。 The service account's name appears in the email address that is provisioned during creation, in the format SA_NAME @ PROJECT_ID .服务帐户的名称显示在创建期间提供的电子邮件地址中,格式SA_NAME @ PROJECT_ID

For more information this document can be referred.有关更多信息,可以参考此文档

Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.将答案发布为社区 wiki,以造福于将来可能会遇到此用例的社区。

Feel free to edit this answer for additional information.请随意编辑此答案以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM