Ano*_*ous 14 google-oauth google-api-python-client google-admin-sdk google-workspace
我编写了一个 Python 脚本(Google_add.py),用于在 Google Workspace 中创建用户。然而,当它运行时,发生了 AttributeError 。如何解决此错误?
\n\xe3\x83\xbbGoogle_add.py\xe3\x80\x80(摘录\xef\xbc\x89
\nPATH = \'/opt/Google/credentials.json\'\nCLIENT_SECRETS = \'/opt/Google/client_secrets.json\'\ncredentials = None\n\n#If there are credentials\nif os.path.exists(PATH):\n credentials = Credentials.from_authorized_user_file(\n path = PATH,\n scopes = SCOPES)\n\n#If there are no (valid) credentials available\nif not credentials or not credentials.valid:\n if credentials and credentials.expired and credentials.refresh_token:\n credentials.refresh(Request())\n else:\n FLOW = flow.InstalledAppFlow.from_client_secrets_file(\n client_secrets_file = CLIENT_SECRETS,\n scopes = SCOPES)\n credentials = FLOW.run_console()\n with open(PATH, \'w\') as token:\n token.write(credentials.to_json())\nRun Code Online (Sandbox Code Playgroud)\n\xe3\x83\xbb错误消息
\nFile "Google_add.py", line 186, in <module>\nmain()\nFile "Google_add.py", line 172, in main\nFLOW.run_console()\nAttributeError: \'InstalledAppFlow\' object has no attribute \'run_console\'\nRun Code Online (Sandbox Code Playgroud)\n我在编写时参考了以下网站。\n https://github.com/googleapis/google-api-python-client/blob/main/docs/oauth-installed.md#sending-users-to-googles- oauth-20-server \n https://developers.google.com/admin-sdk/directory/v1/quickstart/python?hl=en
\n在脚本中,我想使用用户帐户(而不是服务帐户)进行授权。并且“run_local_server()”方法不起作用,因为我的Linux服务器不是Web服务器(没有httpd、nginx等)。
\n(如果我的文章难以阅读,我很抱歉。)
\nAtt*_*igh 13
扩展上面 George 的答案,github 帖子中可用的库版本是:
google-api-python-client==1.7.2
google-auth==1.8.0
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.1
Run Code Online (Sandbox Code Playgroud)
小智 6
该问题可能是google-api-python-client库与其他库的版本兼容性问题,例如
您只需要确保您的版本google-api-python-client支持您安装到其依赖库的版本。您可以在此处google-api-python-client查看库的完整更改日志
https://googleapis.github.io/google-api-python-client/docs/auth.html
https://googleapis.github.io/google-api-python-client/docs/oauth.html
| 归档时间: |
|
| 查看次数: |
10025 次 |
| 最近记录: |