0
votes

I need to access dataset residing in GCP bigquery through application code on my local machine.

I have created a Project, service account and downloaded json file(containing key) in downloads folder on my local machine.Service account is authorized and all required APIs from GCP are enabled. The problem is with setting GOOGLE_APPLICATION_CREDENTIALS environment variable. Not being able to set it from both cloud shell and windows cmd. The json file with key is currently stored in downloads folder.

  • Do I need to move json file (containing key) from my downloads folder to some specific path on my local machine?
  • How do I set GOOGLE_APPLICATION_CREDENTIALS from cloud shell for the json file that is stored on my local machine in order to access GCP bigquery APIs?

from google.cloud import bigquery

import seaborn as sns

import matplotlib.pyplot as plt

import pandas as pd

import numpy as np

import shutil

sql = """ SELECT pickup_datetime, pickup_longitude, pickup_latitude, dropoff_longitude, dropoff_latitude, passenger_count, trip_distance, tolls_amount, fare_amount, total_amount FROM nyc-tlc.yellow.trips LIMIT 10 """

client = bigquery.Client() trips = client.query(sql).to_dataframe() trips

Error: DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

1

1 Answers

0
votes

This is how to set the path to your credentials:

import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/your/credentials_file.json'