TypeError: method() takes exactly 1 argument (2 given)

TypeError: method() takes exactly 1 argument (2 given)

我正在 python google 驱动器 api, python 2.7.10 on windows 10.

我正在为驱动器服务设置一个实例变量。当我尝试 运行 驱动器服务的一种方法 self.service.files().list() 时,问题就出现了。我相信 python 正在传递对象 self 和字符串 "title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'"有没有办法阻止 python 这样做?

class doorDrive():

def __init__(self, scopes = 'https://www.googleapis.com/auth/drive.metadata.readonly',
             secretFile = 'client_secret.json',
             appName = 'Door Cam'):
    self.SCOPES = scopes
    self.CLIENT_SECRET_FILE = secretFile
    self.APPLICATION_NAME = appName
    self.photoFolderId = ''

    creds = self.getCreds()
    http = creds.authorize(httplib2.Http())
    self.service = discovery.build('drive', 'v2', http=http)
    self.initFolder()

def getCreds(self):
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                               'drive-python-quickstart.json')
    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(self.CLIENT_SECRET_FILE, self.SCOPES)
        flow.user_agent = self.APPLICATION_NAME
        credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials

def initFolder(self):
    folders = self.service.files().list("title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'").execute()['items']

你的最后一行是将查询字符串直接传递给 list(),但你可能应该通过关键字传递它,如下所示:

def initFolder(self):
    folders = self.service.files().list(q="title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'").execute()['items']

现在请注意查询前面的 q=。这将使 Python 作为关键字参数而不是位置参数发送。我认为您的错误正在进一步向下级联,因为该函数的第一个参数实际上是 orderBy.

您可以在此处查看规格:https://developers.google.com/resources/api-libraries/documentation/drive/v2/python/latest/drive_v2.files.html#list