我正在使用google的驱动API构建一个应用程序,我使用的是一个JSON密钥。每当我运行以下代码时:
# 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我收到一条奇怪的错误信息:
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这对我来说是一个非常奇怪的错误,因为我给出了函数2的参数。我的密钥位于一个JSON文件中,所有这些操作都是正确的。
发布于 2018-03-25 21:10:14
来自文档这里
类方法from_json(json_data)反序列化一个JSON序列化的实例。 与to_json()相反。 参数: json_data - dict或string,序列化的JSON (作为字符串或已解析的字典)表示凭据。 返回:来自序列化数据的ServiceAccountCredentials。
所以实际上接受一个论点,而不是两个。
注意,在Python那里有n+1参数(因此您看到错误消息2参数,但有3个参数),因为self被隐式传递给方法,因此当您对对象实例调用一个方法时,您将显式地传递实例本身和参数。
https://stackoverflow.com/questions/49479144
复制相似问题