TypeError:得到了意外的关键字参数“名称”

时间:2018-09-13 02:23:53

标签: python google-api

下面看似简单的代码会引发以下错误

  

回溯(最近一次通话最近):文件“ search.py​​”,第48行,在          pageToken = page_token).execute()文件“ C:\ Users \ Choi \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ googleapiclient \ discovery.py”,   方法中的第716行

     

提高TypeError('获得了意外的关键字参数“%s”'%名称)TypeError:得到了意外的关键字参数“名称”

代码:

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

请问我在做什么错?谢谢。

1 个答案:

答案 0 :(得分:1)

您需要使用引用。让我们来看看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)

此处引发了错误。您有一个错误的说法叫name

According to the documentation,查询应该在参数q中。

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