google-bigquery - 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()
解决方案
解决方案:通过os.environ添加环境变量,就可以了。
推荐阅读
- php - 如何在php中使用“页眉”和“页脚”结构时仅对一页使用自定义CSS
- javascript - 警报未在反应 js 中显示更新状态?
- python - 如何在 python 正则表达式中使用 str.contains 获取所有匹配项?
- javascript - 如果没有子元素,如何将类名添加到元素
- reactjs - 调度两个动作
- java - 如何使用 Java 在 Axe-Core 中使用特定标签运行可访问性测试
- arrays - 在 Google 表格中遇到多个查询问题
- async-await - 挂起函数如何不阻塞主线程?
- python - 我们如何通过 Selenium 中的 tagName 限制抓取
- python - Xlwings 找不到模块