1
votes

I'm following this instruction to write a python code and connect it to bigquery

by using

gcloud init 

I choose a particular account and project

and then I run this code:

from gcloud import bigquery
from gcloud.bigquery import job
from gcloud.bigquery.table import *

# Create a new Google BigQuery client using Google Cloud Platform project
# defaults.
bq = bigquery.Client()

But it seems it connects to a wrong project. How it is possible? Does any one have any experience? this is the error.

Traceback (most recent call last): File "", line 1, in File "C:\Python36-32\lib\site-packages\gcloud\bigquery\dataset.py", line 423, in create method='POST', path=path, data=self._build_resource()) File "C:\Python36-32\lib\site-packages\gcloud\connection.py", line 347, in api_request error_info=method + ' ' + url) gcloud.exceptions.Forbidden: 403 Billing has not been enabled for this project. Enable billing at https://console.cloud.google.com/billing. (POST https://www.googleapis.com/bigquery/v2/projects/decisive-octane-142800/datasets)

The project that I bolded belongs to my another account.

1

1 Answers

1
votes

Project selected in gcloud init is for gcloud cli tool only, and not for the python gcloud library. In fact the two are kind of unrelated (they sort of share same name).

The instructions you provided link for do not ask you to use gcloud init.

You can use gcloud to manage you credentials as described here.

So, instead of

bq = bigquery.Client()

you should specify project explicitly

bq = bigquery.Client(project=YOUR_PROJECT_ID)

It is also possible to specify it via other means as this is deduced by this code but it is better to be explicit as this code makes assumptions which are not guaranteed to be always true.