from pprint import pprint
from Goo_gle import Create_Service
CLIENT_SECRET_FILE = 'Client_Calendar.json'
API_NAME = 'calendar'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
输出:
Traceback (most recent call last): File "d:\Play with code\PROGRAMMINGS\Python\Artificial Inteligence\calen_dar.py", line 2, in <module>
from Goo_gle import Create_Service File "d:\Play with code\PROGRAMMINGS\Python\Artificial Inteligence\Goo_gle.py", line 5, in <module>
from google_auth_oauthlib.flow import Flow, InstalledAppFlow File "C:\Python\lib\site-packages\google_auth_oauthlib\__init__.py", line 21, in <module>
from .interactive import get_user_credentials File "C:\Python\lib\site-packages\google_auth_oauthlib\interactive.py", line 27, in <module>
import google_auth_oauthlib.flow File "C:\Python\lib\site-packages\google_auth_oauthlib\flow.py", line 69, in <module>
import google_auth_oauthlib.helpers File "C:\Python\lib\site-packages\google_auth_oauthlib\helpers.py", line 27, in <module>
from google.auth import external_account_authorized_user ImportError: cannot import name 'external_account_authorized_user' from 'google.auth' (C:\Python\lib\site-packages\google\auth\__init__.py)
我不明白为什么会发生这种情况。 这段代码在过去 3 个月一直有效,但是今天更新 google 库后,出现了这个错误..如何解决这个问题?
看起来与
google-auth-library-python-oauth
模块最近的更改有关:
将 google-auth 升级到 2.13.0 可能会修复它。
使用
google_auth_oauthlib
作为最新版本(0.6.0)时,您将收到该错误。请参阅此链接:https://github.com/googleapis/google-auth-library-python-oauthlib/blob/v0.6.0/google_auth_oauthlib/helpers.py#L27
尝试使用以下命令降级 google-auth-oauthlib lib:
pip install google-auth-oauthlib==0.4.6
或更新您的requirement.txt以添加此行:
...
google-auth-oauthlib==0.4.6
...
将 google-auth-oauthlib==0.6.0 (昨天发布)降级到 0.5.3 解决了我的问题。 感谢@Samik
检查 google-auth 版本:您的虚拟环境中安装的 google-auth 版本可能已过时或不兼容。尝试通过运行升级 google-auth 包:
pip install --升级 google-auth google-auth-oauthlib