gpt4 book ai didi

python - "ImportError: file_cache is unavailable"为 Google 服务帐户 file_cache 使用 Python 客户端时

转载 作者:IT老高 更新时间:2023-10-28 21:44:13 34 4
gpt4 key购买 nike

我正在为 G Suite 使用具有完整域授权的服务帐号。我有一个对 Google 日历具有只读访问权限的脚本。该脚本工作得很好,但是当我“构建”服务时会引发错误(在后台线程上?)。代码如下:

from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
import urllib
import requests
from apiclient.discovery import build

cal_id = "my_calendar_id@group.calendar.google.com"

scopes = ['https://www.googleapis.com/auth/calendar.readonly']
credentials = ServiceAccountCredentials.from_json_keyfile_name('my_cal_key.json', scopes=scopes)
delegated_credentials = credentials.create_delegated('me@mydomain.com')
http_auth = delegated_credentials.authorize(Http())

# This is the line that throws the error
cal_service = build('calendar','v3',http=http_auth)

#Then everything continues to work normally
request = cal_service.events().list(calendarId=cal_id)
response = request.execute()

# etc...

抛出的错误是:

WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect
from google.appengine.api import memcache
ImportError: No module named 'google'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module>
from oauth2client.contrib.locked_file import LockedFile
ImportError: No module named 'oauth2client.contrib.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module>
from oauth2client.locked_file import LockedFile
ImportError: No module named 'oauth2client.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
from . import file_cache
File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module>
'file_cache is unavailable when using oauth2client >= 4.0.0')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0

这里发生了什么,我可以解决这个问题吗?我已尝试重新安装和/或升级 google 软件包。

最佳答案

我在这里聚会有点晚了,但我今天遇到了类似的问题并找到了答案 here

仅解决错误:file_cache is available when using oauth2client >= 4.0.0

解决方案:

将您的 discovery.build() 更改为具有字段 cache_discovery=False

discovery.build(api, version, http=http, cache_discovery=False)

关于python - "ImportError: file_cache is unavailable"为 Google 服务帐户 file_cache 使用 Python 客户端时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40154672/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com