[Solved] google cloud doesn’t work with previous f-string python


This line of code imports the Google Cloud SDK into an object named storage.

import google.cloud import storage

You then declare a string named storage with the contents of the bucket name. This overwrites the previous line of code.

storage=f'gs://{bucket_id}/'

You are then trying to create a Cloud Storage Client object from a string object:

client = storage.Client()

That results in the error message:

AttributeError: 'str' object has no attribute 'Client'

Solution: use different variable names:

import google.cloud import storage

bucket_name="my_bucketname"
//others variables
bucket_uri=f'gs://{bucket_id}/'

client = storage.Client()

1

solved google cloud doesn’t work with previous f-string python