Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress noisy googleapiclient cache_discovery (file_cache) warning #27

Merged
merged 2 commits into from
Oct 16, 2017

Conversation

jasonqng
Copy link
Contributor

@jasonqng jasonqng commented Oct 3, 2017

Currently, if you upload or download with oauth2client>4.0.0, you get the below warning.

>>> import pandas as pd
>>> from df2gspread import df2gspread as d2g
>>> d = [pd.Series([1., 2., 3.], index=['a', 'b', 'c']), pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])]
>>> df = pd.DataFrame(d)
>>> d2g.upload(df, "Test df2gspread spreadsheet", "worksheet1", df_size = True)
>> file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
  File "/Users/jasonng/anaconda2/lib/python2.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
    from . import file_cache
  File "/Users/jasonng/anaconda2/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
<Worksheet 'worksheet1' id:or9s3ji>

This PR suppresses this warning using the suggestion in this google-api-client thread: googleapis/google-api-python-client#299.

Tested again with change in this PR, and warning is successfully suppressed and upload still succeeds.

No tests added since this does not affect functionality, merely removes the verbose warning which has minimal (right?) effect on performance.

@maybelinot

@jasonqng jasonqng changed the title Suppress oauth2client file_cache warning Suppress noisy oauth2client cache_discovery (file_cache) warning Oct 3, 2017
@jasonqng jasonqng changed the title Suppress noisy oauth2client cache_discovery (file_cache) warning Suppress noisy googleapiclient cache_discovery (file_cache) warning Oct 3, 2017
@coveralls
Copy link

coveralls commented Oct 3, 2017

Coverage Status

Coverage increased (+0.6%) to 27.686% when pulling c8b99ca on jasonqng:suppress_file_cache_warning into b640361 on maybelinot:master.

@maybelinot
Copy link
Owner

Hi @jasonqng, thanks for contribution!

WDYT if we'll set logging level to the level which is used in df2gspread lib, so users could change logging level when he wants, I don't really want to see this hardcoded.

@jasonqng
Copy link
Contributor Author

jasonqng commented Oct 6, 2017

Sure @maybelinot, that's fine with not hard coding it so long as I don't have to override it every time. Can you suggest or move to wherever it should go? My messy notebooks thank you!

@ghost
Copy link

ghost commented Oct 14, 2017

I am using the master branch of df2gspread. Is this issue still under development? While the output is valid, the errors preceding the output are distracting.

I have used both of the following in the code with no effect.

import logging
logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.CRITICAL)
logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)

The only effective method I have found to suppress these errors is to redirect STDERR to nul or a log file.

The errors I get are:

C:\Users\Glenn\Desktop\gsp2df\rawOut>python gspread2df_test.py

file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
File "C:\Users\Glenn\Anaconda3\lib\site-packages\df2gspread\gspread2df.py", line 66, in download
spsh = gc.open_by_key(gfile)
File "C:\Users\Glenn\Anaconda3\lib\site-packages\gspread\client.py", line 113, in open_by_key
raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Glenn\Anaconda3\lib\site-packages\googleapiclient\discovery_cache_init_.py", line 36, in autodetect
from google.appengine.api import memcache
ImportError: No module named 'google'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Glenn\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 33, in
from oauth2client.contrib.locked_file import LockedFile
ImportError: No module named 'oauth2client.contrib.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Glenn\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 37, in
from oauth2client.locked_file import LockedFile
ImportError: No module named 'oauth2client.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Glenn\Anaconda3\lib\site-packages\googleapiclient\discovery_cache_init_.py", line 41, in autodetect
from . import file_cache
File "C:\Users\Glenn\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 41, in
'file_cache is unavailable when using oauth2client >= 4.0.0')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0

@maybelinot
Copy link
Owner

@jasonqng @gwiensx
I think that disabling discovery caching should be sufficient to avoid this noisy warning:
discovery.build('drive', 'v2', http=http, cache_discovery=False)

What was the intent to change logging level? If there wasn't could you just keep cache_discovery=False option change and I'll merge this one!

Sorry for delayed review..

@jasonqng
Copy link
Contributor Author

jasonqng commented Oct 16, 2017

@jasonqng @gwiensx Reverted the logging setting (so it's back to the default; I don't touch it) and confirmed the warning is still suppressed for me. Can't guarantee it suppresses it for all, but maybe this is a safe incremental step? Thanks for the suggestion!

@coveralls
Copy link

coveralls commented Oct 16, 2017

Coverage Status

Coverage remained the same at 27.083% when pulling b00f330 on jasonqng:suppress_file_cache_warning into b640361 on maybelinot:master.

@maybelinot maybelinot merged commit e9057ff into maybelinot:master Oct 16, 2017
@ghost
Copy link

ghost commented Oct 17, 2017

@maybelinot, @jasonqng My purpose for including the logging business was an attempt to suppress verbosity in discussion of similar errors here. (googleapis/google-api-python-client#299).

I will download and test again using the new code. Thank you

@ghost
Copy link

ghost commented Oct 24, 2017

@maybelinot, @jasonqng On retesting using new gfiles.py, no errors or warnings of any kind!

I'm still learning how this site works, so many thanks for your patience with my floundering questions, and for making this change.

@maybelinot
Copy link
Owner

@gwiensx No problem, thanks for validation 😄

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

Successfully merging this pull request may close these issues.

3 participants