I'm trying to save a bigquery query to a dataframe in a custom Airflow operator.
I've tried using the airflow.contrib.hooks.bigquery_hook and the get_pandas_df method. The task get's stuck on authentication, as it wants me to manually visit a url to authenticate.
As a result, I'm hard coding in authentication. This works, but is definitely not ideal.
Working but not ideal (credentials are hard coded):
def execute(self, context):
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'my-file-location.json'
client = bigquery.Client()
job_config = bigquery.QueryJobConfig()
df = client.query(
self.query,
location="US",
job_config=job_config,).to_dataframe()
Not working:
def execute(self, context):
bq = BigQueryHook(bigquery_conn_id=self.gcp_conn_id, delegate_to=None,use_legacy_sql=True, location='US')
df = bq.get_pandas_df(self.query)
This code get's stuck authenticating. Here is the log: [2019-06-19 12:56:05,526] {logging_mixin.py:95} INFO - Please visit this URL to authorize this application.