“ImportError: file_cache is unavailable” when using Python client for Google service account file_cache

后端 未结 8 1741
孤城傲影
孤城傲影 2021-01-30 16:03

I\'m using a service account for G Suite with full domain delegation. I have a script with readonly access to Google Calendar. The script works just fine, but throws an error (o

相关标签:
8条回答
  • 2021-01-30 16:33

    Tried all the solutions that were listed, but none of them worked. Until I tried the (simple) suggestion from @dtk that was listed somewhere in the comments :

    Install an older version of oauth2client by running:

    pip install oauth2client==3.0.0
    

    Now everything works fine for me. Thank you @dtk !

    0 讨论(0)
  • 2021-01-30 16:40

    to add to the selected answer, if the build function is called by a dependency, and there is no easy way to update it's code, this code can be used to force cache_discovery to be False:

    import googleapiclient.discovery
    
    _build = googleapiclient.discovery.build
    
    
    def no_cache_build(*args, **kw):
        kw["cache_discovery"] = False
        return _build(*args, **kw)
    
    
    googleapiclient.discovery.build = no_cache_build
    
    0 讨论(0)
  • Fwiw this is a reposting of my answer here

    Since they are technically warnings (not errors), if you don't have direct access to the call, you can do this wherever you instantiate the service to suppress them:

    import logging logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR)

    With thanks to theacodes who gave that answer here (but with a missing 'n' in 'client' that seems to have led to a lot of downvotes there).

    See also the discussion here

    0 讨论(0)
  • 2021-01-30 16:44

    The code head of module "google-api-python-client" said...

    install_requires = [
         'httplib2>=0.9.2,<1dev',
         'oauth2client>=1.5.0,<5.0.0dev',    <<=============
         'six>=1.6.1,<2dev',
         'uritemplate>=3.0.0,<4dev',
    ]
    

    So, I have uninstalled oauth2client version 4.0.0

    Then, I have downloaded oauth2client 1.5.2 in a tar.gz file from offial python site https://pypi.python.org/pypi/oauth2client/1.5.2

    I have installed this downloaded file so I have 1.5.2 version of oauth2client

    Package                  Version
    ------------------------ ---------
    certifi                  2016.9.26
    discovery                0.0.4
    distribute               0.7.3
    future                   0.16.0
    google-api-python-client 1.5.5
    httplib2                 0.9.2
    oauth2client             1.5.2
    pefile                   2016.3.28
    pip                      9.0.1
    pyasn1                   0.1.9
    pyasn1-modules           0.0.8
    PyInstaller              3.2
    pypiwin32                219
    requests                 2.11.1
    rsa                      3.4.2
    setuptools               28.8.0
    six                      1.10.0
    uritemplate              3.0.0
    

    After that, ALL is working OK again and there is no warning message.

    0 讨论(0)
  • 2021-01-30 16:53

    I am a bit late to the party here but I had a similar problem today and found the answer here

    Solution to only the error : file_cache is unavailable when using oauth2client >= 4.0.0

    Solution:

    change your discovery.build() to have the field cache_discovery=False i.e

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

    EDIT:

    As @Chronial says this will disable the cache.

    A solution that does not disable the cache can be found here

    0 讨论(0)
  • 2021-01-30 16:55

    I did not want to downgrade my oauth2client. You can use oauth2client 4.1.2 when you set cache_discovery=False for apiclient.discovery.build. This simple solution silenced the error:

    service = discovery.build(api_name, 
                              api_version, 
                              credentials=credentials, 
                              cache_discovery=False)
    

    Source

    0 讨论(0)
提交回复
热议问题