Jupyter 笔记本中 运行 查询的 DefaultCredentialsError
DefaultCredentialsError for running query in Jupyter notebook
我正在关注 this Google 云教程。 运行 Jupyter notebook 中的代码。第 5 步没问题,当我 运行 第 7 步时出现此错误:
DefaultCredentialsError Traceback (most recent call last)
<ipython-input-8-a1696640ccb4> in <module>
----> 1 get_ipython().run_cell_magic('bigquery', '', 'SELECT\n source_year AS year,\n COUNT(is_male) AS birth_count\nFROM `bigquery-public-data.samples.natality`\nGROUP BY year\nORDER BY year DESC\nLIMIT 15\n')
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2379 with self.builtin_trap:
2380 args = (magic_arg_s, cell)
-> 2381 result = fn(*args, **kwargs)
2382 return result
2383
DefaultCredentialsError
表示客户端库尝试用于身份验证的应用程序默认凭据 (ADC) 设置不正确。
您可能错过了设置本地 Jupyter 环境 部分中的步骤,link 用于 Getting Started with Authentication。
简而言之,您需要通过 运行 带有以下代码的单元格来设置您的默认凭据。
export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"
您的路径指向有效的服务帐户密钥文件。
如果您在本地安装了 gcloud sdk,您也许还可以在单元格中设置默认凭据,而不是使用以下内容:
gcloud auth application-default login
我正在关注 this Google 云教程。 运行 Jupyter notebook 中的代码。第 5 步没问题,当我 运行 第 7 步时出现此错误:
DefaultCredentialsError Traceback (most recent call last)
<ipython-input-8-a1696640ccb4> in <module>
----> 1 get_ipython().run_cell_magic('bigquery', '', 'SELECT\n source_year AS year,\n COUNT(is_male) AS birth_count\nFROM `bigquery-public-data.samples.natality`\nGROUP BY year\nORDER BY year DESC\nLIMIT 15\n')
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2379 with self.builtin_trap:
2380 args = (magic_arg_s, cell)
-> 2381 result = fn(*args, **kwargs)
2382 return result
2383
DefaultCredentialsError
表示客户端库尝试用于身份验证的应用程序默认凭据 (ADC) 设置不正确。
您可能错过了设置本地 Jupyter 环境 部分中的步骤,link 用于 Getting Started with Authentication。
简而言之,您需要通过 运行 带有以下代码的单元格来设置您的默认凭据。
export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"
您的路径指向有效的服务帐户密钥文件。
如果您在本地安装了 gcloud sdk,您也许还可以在单元格中设置默认凭据,而不是使用以下内容:
gcloud auth application-default login