When I run the following code on the server (I think, when reading the json file with google application credentials), I get the following error:
JavaScript
x
2
1
TypeError: Object of type 'bytes' is not JSON serializable
2
Json as( source here ):
My Code:
JavaScript
1
36
36
1
import mysql.connector
2
from google.cloud import bigquery
3
import pandas as pd
4
import os
5
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/root/google_credentials.json"
6
def incomes():
7
8
client = bigquery.Client()
9
print("connecting MySql...")
10
mydb = mysql.connector.connect(
11
host='host',
12
user='1111',
13
password='password',
14
database="my_database")
15
16
print ("Connection ok")
17
mycursor = mydb.cursor()
18
mycursor.execute('''query''')
19
20
myresult = mycursor.fetchall()
21
df=pd.DataFrame(myresult,columns=mycursor.column_names)
22
23
24
dataset_ref = client.dataset('dataset')
25
job_config = bigquery.LoadJobConfig()
26
job_config.autodetect = True
27
job_config.write_disposition = "WRITE_TRUNCATE"
28
load_job = client.load_table_from_dataframe(
29
df, 'table_name', job_config=job_config
30
)
31
print("Starting job {}".format(load_job))
32
return ("Done!", 200)
33
34
incomes()
35
36
When I run it with spyder IDE on my local computer with windows installed, there is no problem.
Advertisement
Answer
I solved the problem. The python version installed on the server was 3.6.8. I upgraded this version to python 3.8.12 and the problem was solved.