我是資料工程領域的新手,想使用 Python 創建表并將資料插入 BigQuery,但在此程序中我收到錯誤訊息
,即使我已經通過 shell 設定了 google_application_credential,錯誤訊息仍然出現
這是我的代碼
from google.cloud import bigquery
from google.cloud import language
from google.oauth2 import service_account
import os
os.environ["GOOGLE_APPLICATION_CREDENTIAL"]=r"C:/Users/Pamungkas/Downloads/testing-353407-a3c774efeb5a.json"
client = bigquery.Client()
table_id="testing-353407.testing_field.sales"
file_path=r"C:\Users\Pamungkas\Downloads\sales.csv"
job_config = bigquery.LoadJobConfig(
source_format=bigquery.SourceFormat.CSV, skip_leading_rows=1, autodetect=True,
write_disposition=bigquery.WriteDisposition.WRITE_TRUNCATE #added to have truncate and insert load
)
with open(file_path, "rb") as source_file:
job = client.load_table_from_file(source_file, table_id, job_config=job_config)
job.result() # Waits for the job to complete.
table = client.get_table(table_id) # Make an API request.
print(
"Loaded {} rows and {} columns to {}".format(
table.num_rows, len(table.schema), table_id
)
)
uj5u.com熱心網友回復:
正如@p13rr0m 建議的那樣,您應該使用環境變數GOOGLE_APPLICATION_CREDENTIALS
而不是GOOGLE_APPLICATION_CREDENTIAL
解決您的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/493034.html