python - google.auth.exceptions.RefreshError: ('access_denied: Account restricted' using a domain-wide delegated account
问题描述
我正在尝试在服务帐户上使用域范围的委派从管理 sdk 获取一些信息以生成报告。我有一个已经在工作的代码库,我将它与 gsuite 域一起使用。我想使用相同的代码为另一个域生成报告,所以我为这个另一个域设置了一个 GCP 项目。我创建了一个服务帐户,在其上启用了域范围的委派,并启用了服务帐户的范围。当我尝试进行任何 api 调用模拟域上的任何帐户时,我收到以下错误
adminService.activities().list(userKey='all', applicationName='meet').execute()
google.auth.exceptions.RefreshError: ('access_denied: Account restricted', '{\n "error": "access_denied",\n "error_description": "Account restricted",\n "error_uri":<url>}')
这是我用来创建服务的代码
credentials = service_account.Credentials.from_service_account_file(credentialsPath,
scopes=['https://www.googleapis.com/auth/admin.reports.audit.readonly',
"https://www.googleapis.com/auth/classroom.announcements.readonly",
"https://www.googleapis.com/auth/classroom.courses.readonly",
"https://www.googleapis.com/auth/classroom.coursework.students.readonly",
"https://www.googleapis.com/auth/classroom.profile.emails",
"https://www.googleapis.com/auth/classroom.rosters.readonly",
"https://www.googleapis.com/auth/classroom.student-submissions.students.readonly",
"https://www.googleapis.com/auth/classroom.topics.readonly"
])
delegated_credentials = credentials.with_subject(email)
return build('admin', 'reports_v1', credentials=delegated_credentials)
同样,这不应该是一个编程问题,因为相同的确切代码适用于另一个域,我认为我在 admin/GCP 配置方面遗漏了一些东西,但我不知道是什么,我还没有在互联网上的任何地方都发现了这个确切的错误
解决方案
推荐阅读
- r - 绘制矩阵的三角形,底部对角线
- asynchronous - Rust 预期类型找到的结构
- javascript - 在以下 OR 语句中需要一些明确性,而一个工作正常而另一个不能
- pyspark - 什么是 pyspark.sql.functions.pandas_df() 变体的用例示例,它采用 pd.Series 的迭代器?
- python - 任何 python 解释器都无法识别 Conda mysql 包
- android - 我如何切换此代码以显示在 carousel pro flutter 上
- prolog - Prolog中两个函数的返回值相等
- php - 使用 wp_remote_post 时出现 415 错误“不支持的媒体类型”
- mysql - 如何在 Ubuntu 20.04 上更改 MySQL 中的安全文件私有选项
- javascript - Django如何从javascript向数据库添加数据