1

I am building an app using google's drive API and I am using a JSON API key. Whenever I run the following code:

# these are api managing credentials
scope = ['https://spreadsheets.google.com/spreadsheets']
creds = ServiceAccountCredentials.from_json('client_secret', scope)
client = gspread.authorize(creds)  # this connects the the google api using credentials

I get this weird error message:

File "C:/Users/Will Kaiser's PC/Documents/PyCharm/Projects/ph/main.py", line 16, in <module>
  creds = ServiceAccountCredentials.from_json('client_secret.json', scope)
  TypeError: from_json() takes 2 positional arguments but 3 were given

This to me is a very weird error since I am giving the function 2 arguments. My keys are in a JSON file and all of that is done correctly.

Rafael
  • 7,002
  • 5
  • 43
  • 52

1 Answers1

0

From the documentation here:

classmethod from_json(json_data) Deserialize a JSON-serialized instance.

Inverse to to_json().

Parameters: json_data – dict or string, Serialized JSON (as a string or an already parsed dictionary) representing a credential.

Returns: ServiceAccountCredentials from the serialized data.

So actually accepts 1 argument and not two.

Note that in Python there n+1 arguments (hence you see the error message 2 arguments but three given) because the self is implicitly passed to the method and hence when you call a method on an object instance you are passing the instance itself implicitly plus your arguments explicitly.

Rafael
  • 7,002
  • 5
  • 43
  • 52