Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth #194

Open
thekillgfx opened this issue Apr 18, 2020 · 7 comments

Comments

@thekillgfx
Copy link

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
@kuldeeprishi
Copy link

is there any update on this?

@shcheklein
Copy link
Collaborator

@kuldeeprishi when does this error happen? could you give more context?

@Zukunftsmusik
Copy link

Zukunftsmusik commented Aug 4, 2020

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

@shcheklein
Copy link
Collaborator

@Zukunftsmusik hmm 🤔 it looks like https://github.com/gsuitedevs/PyDrive/blob/master/pydrive/auth.py#L523 already sets cache_discovery=False.

@Zukunftsmusik
Copy link

Zukunftsmusik commented Aug 4, 2020

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.

@Zukunftsmusik
Copy link

Yep, that did it.
thx for the hint 👍

@shcheklein
Copy link
Collaborator

@Zukunftsmusik you can alternatively use PyDrive2 that we maintain. It has a lot of updates and other fixes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants