ArinL
ArinL

Reputation: 1

Google storage.Client throwing .__int__ error: takes 2 positional arguments but 3 were given

When trying to authenticate my local Google credentials to access Google Cloud Storage I'm given the error:

TypeError: init() takes 2 positional arguments but 3 were given

This happens if I run:

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

I've tried adding

credentials, project = google.auth.default(
     scopes=[
         "https://www.googleapis.com/auth/drive",
         "https://www.googleapis.com/auth/cloud-platform",
         'https://www.googleapis.com/auth/devstorage.full_control', 
         'https://www.googleapis.com/auth/devstorage.read_only', 
         'https://www.googleapis.com/auth/devstorage.read_write'
     ]
)

and

storage_client = storage.Client.__init__(self, credentials=credentials, project=project, client_info=None)

but have not been able to resolve the error. Any help appreciated! Let me know if I can provide more context.

The libraries I have installed are:

Upvotes: 0

Views: 786

Answers (2)

ArinL
ArinL

Reputation: 1

Thanks for the help! I was able to resolve this issue with this code:

credentials, project = google.auth.default()

client = storage.Client(project=project)

Upvotes: 0

Javier Roger
Javier Roger

Reputation: 279

Try not to call __init__ directly when instantiating the storage client. Also, note that you put self as a parameter, which is why you are sending one additional positional argument.

Let's try removing those additional args:

storage_client = storage.Client(credentials=credentials, project=project)

Upvotes: 0

Related Questions