I have been using datasheets with a Service Account for a while and it really works like a charm. For a different project, I was planning to use it differently, with a connection to my personal account directly. I thought that datasheets.Client()
would prompt me to the Google Authentication page but I constantly ran into to the same error.
In [1]: import sys
In [2]: print(sys.version)
3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 09:55:02)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
In [3]: import datasheets
In [4]: datasheets.__version__
Out[4]: '0.1.3'
In [5]: datasheets.Client()
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/clientsecrets.py in _loadfile(filename)
120 try:
--> 121 with open(filename, 'r') as fp:
122 obj = json.load(fp)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/PetitLepton/.datasheets/client_secrets.json'
During handling of the above exception, another exception occurred:
InvalidClientSecretsError Traceback (most recent call last)
<ipython-input-4-889d7823daf3> in <module>
----> 1 datasheets.Client()
~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in __init__(self, service, storage, user_agent)
51 self.user_agent = user_agent
52
---> 53 self.http = self._authenticate()
54 self.drive_svc = apiclient.discovery.build('drive', 'v3', http=self.http)
55 # Bind sheets_svc directly to .spreadsheets() as the API exposes no other functionality
~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in _authenticate(self)
87 self.credentials = self._get_service_credentials()
88 else:
---> 89 self.credentials = self._retrieve_client_credentials()
90 return self.credentials.authorize(httplib2.Http())
91
~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in _retrieve_client_credentials(self)
123
124 if not credentials or credentials.invalid:
--> 125 credentials = self._fetch_new_client_credentials(store)
126
127 self.email = credentials.id_token['email']
~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in _fetch_new_client_credentials(self, store)
138 client_secrets_path = os.path.expanduser(unexpanded_client_secrets_path)
139 scope = ('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email')
--> 140 flow = oauth2client.client.flow_from_clientsecrets(client_secrets_path, scope=scope)
141 flow.params['access_type'] = 'offline' # Allow refreshing expired access tokens
142 flow.user_agent = self.user_agent
~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/_helpers.py in positional_wrapper(*args, **kwargs)
131 elif positional_parameters_enforcement == POSITIONAL_WARNING:
132 logger.warning(message)
--> 133 return wrapped(*args, **kwargs)
134 return positional_wrapper
135
~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/client.py in flow_from_clientsecrets(filename, scope, redirect_uri, message, cache, login_hint, device_uri, pkce, code_verifier, prompt)
2133 try:
2134 client_type, client_info = clientsecrets.loadfile(filename,
-> 2135 cache=cache)
2136 if client_type in (clientsecrets.TYPE_WEB,
2137 clientsecrets.TYPE_INSTALLED):
~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/clientsecrets.py in loadfile(filename, cache)
163
164 if not cache:
--> 165 return _loadfile(filename)
166
167 obj = cache.get(filename, namespace=_SECRET_NAMESPACE)
~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/clientsecrets.py in _loadfile(filename)
123 except IOError as exc:
124 raise InvalidClientSecretsError('Error opening file', exc.filename,
--> 125 exc.strerror, exc.errno)
126 return _validate_clientsecrets(obj)
127
InvalidClientSecretsError: ('Error opening file', '/Users/PetitLepton/.datasheets/client_secrets.json', 'No such file or directory', 2)
I apparently misunderstood the behaviour since it is trying to open a secret file which, obviously does not exist.