【发布时间】:2019-03-20 10:10:36
【问题描述】:
我正在尝试通过 Python 客户端查询 BigQuery 数据集。
我有一个启用了结算功能的项目,一个具有 BigQuery 管理员角色的服务帐号,按照此处的说明分配:https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries
这是我正在尝试的代码 sn-p
from google.cloud import bigquery
jsonPath = "/Users/xyz/Downloads/serviceaccount.json"
client = bigquery.Client.from_service_account_json(jsonPath)
query_job = client.query("""
SELECT
CONCAT(
'https://*.com/questions/',
CAST(id as STRING)) as url,
view_count
FROM `bigquery-public-data.*.posts_questions`
WHERE tags like '%google-bigquery%'
ORDER BY view_count DESC
LIMIT 10""")
results = query_job.result()
client.query 调用导致此错误:
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "/Users/xyz/Library/Python/2.7/lib/python/site-
packages/google/cloud/bigquery/client.py", line 1254, in query
query_job._begin(retry=retry)
File "/Users/xyz/Library/Python/2.7/lib/python/site-
packages/google/cloud/bigquery/job.py", line 552, in _begin
method='POST', path=path, data=self._build_resource())
File "/Users/xyz/Library/Python/2.7/lib/python/site-
packages/google/cloud/bigquery/client.py", line 336, in _call_api
return call()
File "/Users/xyz/Library/Python/2.7/lib/python/site-
packages/google/api_core/retry.py", line 260, in retry_wrapped_func
on_error=on_error,
File "/Users/xyz/Library/Python/2.7/lib/python/site-
packages/google/api_core/retry.py", line 177, in retry_target
return target()
File "/Users/xyz/Library/Python/2.7/lib/python/site-
packages/google/cloud/_http.py", line 293, in api_request
raise exceptions.from_http_response(response)
google.api_core.exceptions.Unauthorized: 401 POST .
https://www.googleapis.com/bigquery/v2/projects/xyzproject/jobs: HTTP
Basic Authentication is not supported for this API
关于我可以做些什么来解决这个身份验证问题的任何指针?非常感谢
python -V 2.7.10 我安装了最新的谷歌云库
【问题讨论】:
标签: python authentication google-cloud-platform google-bigquery