簡體   English   中英

TypeError:得到了意外的關鍵字參數“ name”

[英]TypeError: got an unexpected keyword argument “name”

下面看似簡單的代碼將引發以下錯誤

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

引發TypeError('獲得了意外的關鍵字參數“%s”'%名稱)TypeError:得到了意外的關鍵字參數“ name”

碼:

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

請問我做錯了什么? 謝謝。

您需要使用引用。 讓我們看看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

根據文檔 ,查詢應在參數q

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM