Azure / pykusto

Query Kusto like a pro from the comfort of your Jupyter notebook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow `use_global_cache=True` with any authentication method

ymost opened this issue · comments

Use case: researcher was using pykusto from a Data Bricks notebook, and the default Azure CLI authentication was failing with the exception below.
When they provided their own KustoClient instance, they could no longer use use_global_cache.

FileNotFoundError Traceback (most recent call last) /databricks/python/lib/python3.7/site-packages/azure/cli/core/_session.py in load(self, filename, max_age) 47 self.save() ---> 48 with codecs_open(self.filename, 'r', encoding=self._encoding) as f: 49 self.data = json.load(f) /local_disk0/.ephemeral_nfs/envs/pythonEnv-55cda8d1-9409-4809-af73-a9a8df6e827b/lib/python3.7/codecs.py in open(filename, mode, encoding, errors, buffering) 903 mode = mode + 'b' --> 904 file = builtins.open(filename, mode, buffering) 905 if encoding is None: FileNotFoundError: [Errno 2] No such file or directory: '/root/.azure/azureProfile.json' During handling of the above exception, another exception occurred: FileNotFoundError Traceback (most recent call last) <command-1366941365999876> in <module> 8 9 # Use the client when creating the PyKustoClient ---> 10 client = PyKustoClient(cluster,use_global_cache=True) /databricks/python/lib/python3.7/site-packages/pykusto/_src/client.py in __init__(self, client_or_cluster, fetch_by_default, use_global_cache, retry_config) 119 else: 120 --> 121 self.__client = (self._cached_get_client_for_cluster if use_global_cache else self._get_client_for_cluster)(client_or_cluster) 122 self.__cluster_name = client_or_cluster 123 self._refresh_if_needed() /databricks/python/lib/python3.7/site-packages/pykusto/_src/client.py in _cached_get_client_for_cluster(cluster) 178 Provided for convenience during development, not recommended for general use. 179 """ --> 180 return PyKustoClient._get_client_for_cluster(cluster) 181 182 def _internal_get_items(self) -> Dict[str, 'Database']: /databricks/python/lib/python3.7/site-packages/pykusto/_src/client.py in _get_client_for_cluster(cluster) 164 # As a workaround, we first attempt to manually get the Azure CLI token, and see if it works. 165 # Get rid of this workaround once this is resolved: https://github.com/Azure/azure-kusto-python/issues/240 --> 166 stored_token = _get_azure_cli_auth_token() 167 if stored_token is None: 168 _logger.info("Failed to get Azure CLI token, falling back to AAD device authentication") /databricks/python/lib/python3.7/site-packages/azure/kusto/data/security.py in _get_azure_cli_auth_token() 30 31 azure_folder = get_config_dir() ---> 32 ACCOUNT.load(os.path.join(azure_folder, "azureProfile.json")) 33 profile = Profile(storage=ACCOUNT) 34 token_data = profile.get_raw_token()[0][2] /databricks/python/lib/python3.7/site-packages/azure/cli/core/_session.py in load(self, filename, max_age) 59 "Failed to load or parse file %s. It will be overridden by default settings.", 60 self.filename) ---> 61 self.save() 62 63 def save(self): /databricks/python/lib/python3.7/site-packages/azure/cli/core/_session.py in save(self) 63 def save(self): 64 if self.filename: ---> 65 with codecs_open(self.filename, 'w', encoding=self._encoding) as f: 66 json.dump(self.data, f) 67 /local_disk0/.ephemeral_nfs/envs/pythonEnv-55cda8d1-9409-4809-af73-a9a8df6e827b/lib/python3.7/codecs.py in open(filename, mode, encoding, errors, buffering) 902 # Force opening of the file in binary mode 903 mode = mode + 'b' --> 904 file = builtins.open(filename, mode, buffering) 905 if encoding is None: 906 return file FileNotFoundError: [Errno 2] No such file or directory: '/root/.azure/azureProfile.json'