I recently developed a python code in my local machine that read data from mysql database and insert in google big query.I use service account for authentication purpose and my code can be executed successfully without error. Now I am trying to run my script in a docker python container. Once I run my code, receive the a authentication message which I am not sure how to handle it automatically without interaction between user and system.
Message is :
"Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=4xxxxxxxk0tmvj2m941jhre2nbqka17vqxxfxxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%xxxxxxxb&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbigquery&state=kszePnO3tOxxxxxx&prompt=consent&access_type=offline Enter the authorization code: Traceback (most recent call last):... .........
EOFError: EOF when reading a line "
My Python code:
import mysql.connector
import pandas as pd
from oauth2client.client import GoogleCredentials
from bigquery import get_client
import os
import urllib.request
service_account = '[email protected]'
key = 'xxxxxxxxx.p12'
project_id = 'xxxxxxxxx'
db = mysql.connector.connect(user=$user,
password=$password,host=$host,database=$database)
df= pd.read_sql(sql_query,db)
....
client = get_client(project_id, service_account=service_account,
private_key_file=key, readonly=False)
#Push dataframe to google bigquery
df.to_gbq('GoogleBQDatbaseName.TableName',projectid,verbose=True,if_exists='append')
Any suggestion how I can handle this authentication issue in my script automatically. Thank you