调用GoogleAuth.LocalWebserverAuth()提示缺少self参数,如何解决?
解决GoogleAuth.LocalWebserverAuth()缺少self参数的错误
错误原因
你没有正确实例化GoogleAuth类:gauth = GoogleAuth只是将变量指向类本身,而非创建类的实例。LocalWebserverAuth是实例方法,必须通过类的实例调用,直接用类调用会触发missing 'self'参数的错误。另外原代码还缺少GoogleAuth的导入语句,会导致NameError。
修正步骤
- 补充
GoogleAuth的导入语句 - 给
GoogleAuth加上括号,创建类的实例
修正后的代码
from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive gauth = GoogleAuth() gauth.LocalWebserverAuth() drive = GoogleDrive(gauth)
内容的提问来源于stack exchange,提问作者lungsang
相关产品推荐
相关产品推荐

