Как можно отлавливать ответ от BigQuery?

Есть такая ошибка, как решить ее я в курсе
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.


Как поймать сам код статуса? (403, 200,)
Сам код
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)
  • Вопрос задан
  • 85 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы