我正在尝试对一个应用程序进行 docker 化,该应用程序对 bigquery 进行数据调用,我提供了凭据 .json(尝试通过 oauth-service 帐户进行身份验证),但我面临的是当我运行我的应用程序运行的容器时,但它当我通过笔记本电脑上的 jupyter 或云功能(GCP)简单地运行脚本时,要求提供身份验证码它使用 .json 并进行身份验证并提供数据。
愿意将此容器部署到云运行。我在这里做错了什么?任何帮助都会很棒!
我用来对 bigquery 进行 api 调用的示例方法。
PS:不是算法代码,但这只是我想要工作的方法,即对 bigquery 的 api 调用。在这段代码中也面临同样的问题。
def pfy_algorithm_1_1():
import pandas as pd
import numpy as np
import datetime
import requests
import json
from pandas import json_normalize
from google.cloud import bigquery
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file('mylo_bigquery.json')
project_id = 'xyz'
client = bigquery.Client(credentials= credentials,project=project_id)
user_data=query_big_query('''select * from dataset_id.table_id limit 5''')
destination_table1 = 'dataset-id.table-id'
if_exists='replace'
private_key='mylo_bigquery.json'
authcode = 'xyz1xyz23'
user_data.to_gbq(destination_table = destination_table1,
project_id = project_id,
chunksize=None,
reauth=False,
if_exists=if_exists,
auth_local_webserver=False,
table_schema=None)
码头文件:
#setting base image
FROM python:3
#setting the working directory in the container
WORKDIR /usr/src/app
#copy the dependencies file to working directory
COPY . .
#installing dependencies
RUN pip install -r requirements.txt
#command to run on container start
EXPOSE 8080
ENTRYPOINT ["python3","main.py"]