This is related to https://github.com/google/google-api-python-client/pull/294
After upgrading google-api-python-client and oauth2client I get:
Oct 23 11:26:30 admin [11:26:30][WARNING] googleapiclient.discovery_cache init.py:autodetect:44 | file_cache is unavailable when using oauth2client >= 4.0.0#012Traceback (most recent call last):#012 File "/usr/share/python/.../local/lib/python2.7/site-packages/googleapiclient/discovery_cache/init.py", line 41, in autodetect#012 from . import file_cache#012 File "/usr/share/python/..../local/lib/python2.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in
#012 'file_cache is unavailable when using oauth2client >= 4.0.0')#012ImportError: file_cache is unavailable when using oauth2client >= 4.0.0
I know that it was added to add oauth2client support (which I appreciate) and from what I can see doesn't actually abort any action - but would it be possible to remove the WARNING as well - or is it meant as a future todo?
It's not a huge issue, but possibly confusing to others - not to mention my eyes stopping at it every time I view any logs or monitoring.
You can silence this the same way you can silence any other log using the standard library logging infrastructure:
import logging
logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)
Of course you can! I apologize, I blame the lack of coffee for my ignorance.
No worries. :)
Are we sure that this is that simple? I have a project that I'm getting reports of seizing/crashing/weirdness with and I'm seeing these all over the log (no other issues):
2016-12-08 20:11:27,816 [googleapiclient.discovery_cache WARNING] file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
from . import file_cache
File "/usr/lib/python2.7/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
These are ImportErrors, not just mere log verbosity. Thoughts?
It's worth mentioning that my version reference to google-api-python-client hasn't changed in over 2.5 years. I can't fathom why I haven't seen this error before and why it appears to be an issue now. But, it does appear to be an exception which must be disrupting something whether it's specifically related to my user's issue or something silent from the logs is responsible for that.
@dsoprea if you silence the logs as above, do you still see the stacktrace?
@jonparrott I've asked. Thanks.
I apologize to comment on closed issue, but is there any performance penalty when the file_cache is not used with oauth2client 4.0.0? I.e. should I keep the oauth2client 3.0.0 or may I safely upgrade and ignore the warning? Thanks.
It seems to be the better way to silence this error, if one does not care about the cache, is to simply specify cache_discovery=False when performing discovery.build() -- this avoids the broken code path.
maxrp solution worked (python3.6) for most logging message: discovery.build('drive', 'v3', http=http, cache_discovery=False)
but I also needed to set the logging level of the googleapiclient.discovery using jonparrott proposition:
logging.getLogger('googleapiclient.discovery').setLevel(logging.CRITICAL)
jonparrott's answer almost worked for me.... you just have to fix the typo:
import logging
logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR)
as per this answer disable it adding cache_discovery=False in discover.build(api, version, http=http, cache_discovery=False)
OMG, I could kiss you guys. I've been shoving beans up my nose for days trying to find the cause of the empty rows. Confirmed: change scope and re-auth fixes the problem.
For anybody else looking for this: The open issue tracking this is #325. It also contains some better workarounds.
It seems to be the better way to silence this error, if one does not care about the cache, is to simply specify cache_discovery=False when performing discovery.build() -- this avoids the broken code path.
EXCELLENT! that worked for me.
when calling the auth I just added cache_discovery=False as a new parameter
service = build('admin', 'directory_v1', cache_discovery=False, http=creds.authorize(Http()))
GCP_discovery.build('compute', 'v1', credentials=self.credentials, cache_discovery=False)
@khushbuparakh If you have this issue, please open a new issue (or comment on one that is currently open). Unfortunately it's easy for us to miss comments added to closed issues.
Most helpful comment
It seems to be the better way to silence this error, if one does not care about the cache, is to simply specify cache_discovery=False when performing discovery.build() -- this avoids the broken code path.