I am trying to query a BigQuery dataset through a Python client.
I have a project with billing enabled, a service account with BigQuery admin role assigned as instructed here:https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries
This is the code snippet I am trying
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://stackoverflow.com/questions/',
CAST(id as STRING)) as url,
view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE tags like '%google-bigquery%'
ORDER BY view_count DESC
LIMIT 10""")
results = query_job.result()
The client.query invocation results in this error:
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
Any pointers on what I can do to resolve this authentication hiccup? Thanks so much
python -V 2.7.10 I have latest google cloud libraries installed