试图通过QuickStart Guide,我得到了
>>> from google.oauth2.credentials import Credentials
Traceback (most recent call last):
File "<python-input-8>", line 1, in <module>
from google.oauth2.credentials import Credentials
ModuleNotFoundError: No module named 'google'
>>> from google_auth_oauthlib.flow import InstalledAppFlow
Traceback (most recent call last):
File "<python-input-9>", line 1, in <module>
from google_auth_oauthlib.flow import InstalledAppFlow
ModuleNotFoundError: No module named 'google_auth_oauthlib'
>>> from googleapiclient.discovery import build
Traceback (most recent call last):
File "<python-input-10>", line 1, in <module>
from googleapiclient.discovery import build
ModuleNotFoundError: No module named 'googleapiclient'
尽管有以下内容
pip freeze
试图在colab环境中跑步时,我会得到以下
beautifulsoup4==4.11.2
cachetools==5.3.0
certifi==2022.12.7
charset-normalizer==3.1.0
google==3.0.0
google-api-core==2.11.0
google-api-python-client==2.81.0
google-auth==2.16.2
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
googleapis-common-protos==1.58.0
warge warge的部分问题在进行了更多的问题之后!
,事实证明,我处于一个怪异的状态,在我的机器上安装了包装。因此,尽管显示我已经安装了所需的软件包,但某些东西(我实际上不知道)导致
RefreshError Traceback (most recent call last)
<ipython-input-15-3a42be915110> in <cell line: 0>()
20 , SCOPES
21 )
---> 22 creds.refresh(Request())
23 # If there are no (valid) credentials available, let the user log in.
24 if not creds or not creds.valid:
2 frames
/usr/local/lib/python3.11/dist-packages/google/oauth2/_client.py in _handle_error_response(response_data, retryable_error)
67 error_details = json.dumps(response_data)
68
---> 69 raise exceptions.RefreshError(
70 error_details, response_data, retryable=retryable_error
71 )
RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})
无法找到 /源 /使用它们。 我能够通过使用
pip freeze
??这是我在工作目录中采取的具体步骤:
python
QuickStartGuide)将其下载到我的工作目录中。请注意,由于我与2023年的工作目录相同,因此我将旧的凭据/令牌文件重命名为
venv
,以便QuickStart中的auth Flow(和我的其他功能)可以从新文件中读取(我将其简单地重命名为python -m venv venv
source venv/bin/activate
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
)。
如果我有时间调试COLAB流(它使用相同的文件 /代码,只需在使用this Answer访问它们时更新到我的Google驱动器),我将在此处更新我的答案!