A
A
Artem Andreev2019-07-16 14:57:11
Google Cloud Platform
Artem Andreev, 2019-07-16 14:57:11

How can I catch a response from BigQuery?

There is a bug, I know how to solve it

Traceback (most recent call last):
  File "connect.py", line 13, in <module>
    print(pd.read_gbq(query, project_id=project_id, credentials=credentials, dialect='standard'))
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\gbq.py", line 149, in read_gbq
    credentials=credentials, verbose=verbose, private_key=private_key)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 927, in read_gbq
    final_df = connector.run_query(query, configuration=configuration)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 499, in run_query
    self.process_http_error(ex)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 404, in process_http_error
    raise GenericGBQException("Reason: {0}".format(ex))
pandas_gbq.gbq.GenericGBQException: Reason: 403 Billing has not been enabled for this project. Enable billing at https://console.cloud.google.com/billing. DML queries are not allowed in the free tier. Set up a billing account to remove this restriction.
PS C:\Users\Artem_Andreev\Desktop\nirvanna\cgi-bin> python connect.py
Traceback (most recent call last):
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 497, in run_query
    rows_iter = query_reply.result()
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\google\cloud\bigquery\job.py", line 2877, in result
    super(QueryJob, self).result(timeout=timeout)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\google\cloud\bigquery\job.py", line 733, in result
    return super(_AsyncJob, self).result(timeout=timeout)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\google\api_core\future\polling.py", line 127, in result
    raise self._exception
google.api_core.exceptions.Forbidden: 403 Billing has not been enabled for this project. Enable billing at https://console.cloud.google.com/billing. DML queries are not allowed in the free tier. Set up a billing account to remove this restriction.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "connect.py", line 14, in <module>
    df = pd.read_gbq(query, project_id=project_id, credentials=credentials, dialect='standard').result()
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\gbq.py", line 149, in read_gbq
    credentials=credentials, verbose=verbose, private_key=private_key)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 927, in read_gbq
    final_df = connector.run_query(query, configuration=configuration)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 499, in run_query
    self.process_http_error(ex)
  File "C:\Users\Artem_Andreev\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_gbq\gbq.py", line 404, in process_http_error
    raise GenericGBQException("Reason: {0}".format(ex))
pandas_gbq.gbq.GenericGBQException: Reason: 403 Billing has not been enabled for this project. Enable billing at https://console.cloud.google.com/billing. DML queries are not allowed in the free tier. Set up a billing account to remove this restriction.

How to catch the status code itself? (403, 200,)
Code itself
import pandas as pd
import requests
import cgi
import json
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file(
    '08361c47b.json')
query = #запрос

df = pd.read_gbq(query, project_id=project_id, credentials=credentials, dialect='standard')
print(df)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question