简体   繁体   中英

TypeError: got an unexpected keyword argument “name”

The seemingly simple code below throws the following error

Traceback (most recent call last): File "search.py", line 48, in pageToken=page_token).execute() File "C:\\Users\\Choi\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\googleapiclient\\discovery.py", line 716, in method

raise TypeError('Got an unexpected keyword argument "%s"' % name) TypeError: Got an unexpected keyword argument "name"

Code:

scope = 'https://www.googleapis.com/auth/drive'
credentials = ServiceAccountCredentials.from_json_keyfile_name('pyGD-eadb4d7ba057.json', scope)
http = credentials.authorize(httplib2.Http())
drive_service = discovery.build('drive', 'v3', http=http)
page_token = None
print('While START::::')
while True:
    response = drive_service.files().list(name = 'hello',
                                            spaces='drive',
                                            fields='nextPageToken, files(id, name)',
                                            pageToken=page_token).execute()
    for file in response.get('files', []):
        #Process change
        print('RESULT::::')
        print ('Found file: %s (%s)' % (file.get('name'), file.get('id')))
    page_token = response.get('nextPageToken',None)
    if page_token is None:
        break

What am I doing wrong please? Thank you.

You need to use the trackback. Let's have a look at googleapiclient/discovery.py

def method(self, **kwargs):
# Don't bother with doc string, it will be over-written by createMethod.

    for name in six.iterkeys(kwargs):
        if name not in parameters.argmap:
>>          raise TypeError('Got an unexpected keyword argument "%s"' % name)

The error was raised here. You have a wrong argument called name .

According to the documentation , the query should be in argument q .

response = drive_service.files().list(q="name='hello'",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM