首页 > 解决方案 > BigQuery:在自动化作业中询问的凭据

问题描述

我有一个 python 应用程序/作业将数据帧推送到 BigQuery。然而,这项工作失败了,因为显然它要求提供如下所示的凭据:

请访问此 URL 以授权此应用程序:

由于这是一项自动化工作,我无法单击链接并提交代码。有没有其他方法可以通过授权?

我已经在我的环境变量/bashrc 中设置了服务帐户密钥。

代码

from datetime import timedelta
import pandas as pd
from io import StringIO
from azure.storage.blob import BlockBlobService


class Transmitter:

    def __init__(self):
            self.blob_service = BlockBlobService(account_name='xxxx',
                                                 account_key='xxxxxxxxxxxxx')
            self.dataset_id = 'xxxx'
            self.jobQuery = "select JobID, EmailName from xxxxx group by JobID, EmailName"
            self.keyDf = pd.read_csv('jobKeys.csv')

    def toBigQJobs(self):

        jDf = pd.read_gbq(self.jobQuery, project_id='xxxx', dialect='standard')

        jDf['Type'] = 'C'
        jDf['Category'] = 'other'
        for index, row in jDf.iterrows():
            for indexA, rowA in self.keyDf.iterrows():
                    if rowA['Key'] in row['EmailName']:
                            jDf.loc[index, 'Category'] = rowA['Category']
                            jDf.loc[index, 'Type'] = rowA['Type']
                            break

        jDf.to_gbq(destination_table='xxxx', project_id='xxxx',
                    if_exists='replace')

if __name__ == '__main__':

    objTransmitter = Transmitter()

    objTransmitter.toBigQJobs()

标签: google-bigquery

解决方案


解决方案:通过os.environ添加环境变量,就可以了。


推荐阅读