我正在使用G套件的服务帐户和完全域委派。我有一个对谷歌日历只读访问的脚本。脚本运行得很好,但是抛出了一个错误(在后台线程上?)当我“建立”服务时。代码如下:
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
包。
要使用Google API for Python客户端,您需要首先安装它,因为googleapi不是Python模块中内置的。指令在Install the Library中找到。
安装
您可以使用包管理器,也可以手动下载并安装Python客户端库:
托管安装
使用pip或setuptools管理安装(可能需要先运行sudo):
pip(首选):
$ pip install --upgrade google-api-python-client
Setuptools:使用Setuptools包中包含的easy_install工具:
$ easy_install --upgrade google-api-python-client
“googleapipythonclient”模块的代码负责人说。。。
所以,我已经卸载了oauth2client版本4.0.0
然后,我从正式的python站点https://pypi.python.org/pypi/oauth2client/1.5.2下载了tar.gz文件中的oauth2client 1.5.2
我已经安装了这个下载的文件,所以我有1.5.2版本的oauth2client
之后,一切又恢复正常,没有任何警告信息。
我来这里的聚会有点晚了,但我今天遇到了一个类似的问题,找到了答案
仅解决错误:
file_cache is unavailable when using oauth2client >= 4.0.0
解决方案:
将
discovery.build()
更改为具有字段cache_discovery=False
i、 e类编辑:
正如@Chronial所说,这将禁用缓存。
找不到禁用缓存的解决方案here
相关问题 更多 >
编程相关推荐