Salman P
Salman P

Reputation: 1

Reading file content from Cloud Storage

I have been trying to read contents of a json file from Google Cloud Storage and encounter an error. Here is my code

from google.cloud import storage
import jsonclient = storage.Client()
bucket = client.get_bucket('bucket_name')
blob = bucket.get_blob('file.json')
u = blob.download_as_string()
print(u)

I see following error

TypeError: request() got an unexpected keyword argument 'data'

pretty much lost. Help is appreciated

Upvotes: 0

Views: 928

Answers (1)

Andrei Cusnir
Andrei Cusnir

Reputation: 2805

You don't have to import the Client(), you just have to declare it like

client = storage.Client().

Use the code below to load the JSON file from Google Cloud Storage bucket. I have tested it myself and it is working.

from google.cloud import storage
client = storage.Client()

BUCKET_NAME = '[BUCKET_NAME]'
FILE_PATH = '[path/to/file.json]'

bucket = client.get_bucket(BUCKET_NAME)
blob = bucket.get_blob(FILE_PATH)
print('The JSON file is: ')
print(blob.download_as_string())

Replace the [BUCKET_NAME] with your bucket's name and the [path/to/file.json] to the path where your JSON file is located inside the bucket.

Upvotes: 1

Related Questions