0

I'm new into data engineering field, and want to create table and inserting the data to BigQuery using Python, but in the process I got error message enter image description here even though I already set the google_application_credential through the shell, the error message still appear

here is my code

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
    )
)
3
  • 1
    s is missing at the end Commented Jun 16, 2022 at 6:27
  • which one? can you pointing out? @p13rr0m Commented Jun 16, 2022 at 6:41
  • 3
    You have GOOGLE_APPLICATION_CREDENTIAL, but it is GOOGLE_APPLICATION_CREDENTIALS Commented Jun 16, 2022 at 6:45

1 Answer 1

1

As @p13rr0m suggested, you should have to use the environment variable as GOOGLE_APPLICATION_CREDENTIALS instead of GOOGLE_APPLICATION_CREDENTIAL to resolve your issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.