This is - as per request in the original #427 - a follow-up issue.
The function documentation says:
Detects an appropriate cache module and returns it. Returns
googleapiclient.discovery_cache.base.Cache, a cache object which is auto detected, orNoneif no cache object is available.
Exceptions in this context only provide a pythonic way to do control flow, and do not indicate anomalies or malfunctioning of the code. None is a perfectly fine, as-per-specifications behaviour. The correct level should probably be INFO.
Also, even if you would stand by the WARNING level, you should tidy up the messy log message. This is what the user is met with:
```WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
File "/home/mac/dev/flashfaces/flashfaces/lib/python3.8/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 "/home/mac/dev/flashfaces/flashfaces/lib/python3.8/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in
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 "/home/mac/dev/flashfaces/flashfaces/lib/python3.8/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in
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/mac/dev/flashfaces/flashfaces/lib/python3.8/site-packages/googleapiclient/discovery_cache/__init__.py", line 42, in autodetect
from . import file_cache
File "/home/mac/dev/flashfaces/flashfaces/lib/python3.8/site-packages/googleapiclient/discovery_cache/file_cache.py", line 40, in
raise ImportError(
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
```
A saner way to to communicate with the user could potentially be:
WARNING - No caching available (file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth)
Simply removing exc_info=True from this line would suffice (I made a fork just to do this).
Same/similar issue here.
Getting the following when instantiating a Google Drive client:
WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
File "/Users/dpell/src/.../.venv/lib/python3.8/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/dpell/src/.../.venv/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 "/Users/dpell/src/.../.venv/lib/python3.8/site-packages/googleapiclient/discovery_cache/__init__.py", line 44, in autodetect
from . import file_cache
File "/Users/dpell/src/.../.venv/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
WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
File "/Users/dpell/src/.../.venv/lib/python3.8/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/dpell/src/.../.venv/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 "/Users/dpell/src/.../.venv/lib/python3.8/site-packages/googleapiclient/discovery_cache/__init__.py", line 44, in autodetect
from . import file_cache
File "/Users/dpell/src/.../.venv/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
This is causing issues in our monitoring stack because we consider logs with 'Traceback' in them to be unhandled exceptions and this warning message results in false positives.
So far my solution has been to lock oauth2client under 1.5.2, which is what I get when specifying < 4.0.0 in my requirements.txt.
Any idea when this might be merged?
The log output takes up way too much space and occurs way too frequently (every search causes it to be repeated), which just makes logs a chore to go through. I can understand showing all of this in the first search but repeating it every time is just annoying.
I've used the method proposed by @davidcpell to lower the oauth2client to 1.5.2, which works well. However, an exception is generated if I have logging turned on in our code when using the latest version of the oauth2client.
Any idea when this is likely to fixed?
@mysticaltech Thank you. That worked well!
Linking #1061 as it is related.
Most helpful comment
Same/similar issue here.
Getting the following when instantiating a Google Drive client:
This is causing issues in our monitoring stack because we consider logs with 'Traceback' in them to be unhandled exceptions and this warning message results in false positives.
So far my solution has been to lock
oauth2clientunder 1.5.2, which is what I get when specifying < 4.0.0 in myrequirements.txt.