file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
thekillgfx opened this issue ยท 7 comments
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.8/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module>
from oauth2client.locked_file import LockedFile
ModuleNotFoundError: No module named 'oauth2client.locked_file'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.8/site-packages/googleapiclient/discovery_cache/__init__.py", line 42, in autodetect
from . import file_cache
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.8/site-packages/googleapiclient/discovery_cache/file_cache.py", line 40, in <module>
raise ImportError(
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
is there any update on this?
@kuldeeprishi when does this error happen? could you give more context?
I'm getting the same error.
According to googleapis/google-api-python-client#299 you either need to change the logging level
import logging logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR)
or disable the cache adding cache_discovery=False
in discover.build(api, version, http=http, cache_discovery=False)
The former does not suffice imo. I don't wanna suppress warnings, I'd like them not to occur.
The latter can't be done through PyDrive, it seems.
For me this happens when I initialize the drive object multiple times (I have to do this, since the credential file gets deleted regularly on my hoster (Heroku)) and then try to list files on gdrive.
Code
Initializing
gauth: pydrive.auth.GoogleAuth = pydrive.auth.GoogleAuth(settings_file=settings_file_path)
credentials = pydrive.auth.ServiceAccountCredentials.from_json_keyfile_name(service_account_file_path, scopes)
gauth.credentials = credentials
drive: pydrive.drive.GoogleDrive = pydrive.drive.GoogleDrive(gauth)
ListFiles
This is where the error occurs, after having initialized the client 2 times in short succession.
file_list = drive.ListFile({'q': f'\'{self._folder_id}\' in parents and title contains \'{file_name_part}\''}).GetList()
Full error message
[WARNING ] googleapiclient.discovery_cache: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
File "/Users/[...]/.pyenv/versions/3.6.9/lib/python3.6/site-packages/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect
from google.appengine.api import memcache
ModuleNotFoundError: No module named 'google.appengine'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/[...]/.pyenv/versions/3.6.9/lib/python3.6/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module>
from oauth2client.contrib.locked_file import LockedFile
ModuleNotFoundError: No module named 'oauth2client.contrib.locked_file'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/[...]/.pyenv/versions/3.6.9/lib/python3.6/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module>
from oauth2client.locked_file import LockedFile
ModuleNotFoundError: No module named 'oauth2client.locked_file'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/[...]/.pyenv/versions/3.6.9/lib/python3.6/site-packages/googleapiclient/discovery_cache/__init__.py", line 42, in autodetect
from . import file_cache
File "/Users/[...]/.pyenv/versions/3.6.9/lib/python3.6/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module>
"file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth"
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
@Zukunftsmusik hmm ๐ค it looks like https://github.com/gsuitedevs/PyDrive/blob/master/pydrive/auth.py#L523 already sets cache_discovery=False
.
That's odd. I'm running version 1.3.1 (updated 2016 according to PyPi) and the warning occurs.
The file above has been changed in 2018.
I'll try using git+https://github.com/googledrive/PyDrive.git#egg=PyDrive
instead.
Yep, that did it.
thx for the hint ๐
@Zukunftsmusik you can alternatively use PyDrive2 that we maintain. It has a lot of updates and other fixes.