오류가 발생하는 이유 "TypeError : Method ()는 디렉토리 API를 사용하여 Python에서 정확히 1 인수 (2)를 취하는 이유는 무엇입니까?

StackOverflow https://stackoverflow.com/questions/19842347

문제

Google Apps 도메인 내에서 조직 장치와 함께 작동하는 명령 줄 스크립트를 작성하려고합니다. 따라서 Google의 많은 복잡한 문서를 사용하여 API 콘솔에서 응용 프로그램을 성공적으로 작성하고 관리자 SDK를 켜고 스크립트 내에서 성공적으로 연결했습니다. 그러나 디렉토리 서비스 객체를 만들 때 (성공한 것처럼 보이는) 디렉토리 서비스 객체를 만들 때 해당 메시지를 받기 때문에 상호 작용하는 데 문제가 있습니다. Python API 패키지도 설치했습니다. 내 현재 코드는 다음과 같습니다.

import argparse
import httplib2
import os
import sys
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

f = file("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12", "rb")
key = f.read()
f.close()

credentials = SignedJwtAssertionCredentials(
    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com",
    key,
    scope = "https://www.googleapis.com/auth/admin.directory.orgunit"
)

http = httplib2.Http()
http = credentials.authorize(http)

directoryservice = build("admin", "directory_v1", http=http)
orgunits = directoryservice.orgunits()

thelist = orgunits.list('my_customer')

해당 코드를 실행하면 오류 메시지를받습니다.

Traceback (most recent call last):
  File "test.py", line 33, in <module>
    orgunits.list('my_customer')
TypeError: method() takes exactly 1 argument (2 given)

"my_customer"별칭을 사용하지 않고 시도했지만 오류는 내가 제공하지 않았다고 불평합니다. 어떤 도움이든, 나는 오랫동안 Python을 사용하지 않았습니다. 사용자 오류 일 수 있습니다.

도움이 되었습니까?

해결책

Google Apps API에 익숙하지는 않지만

orgunits.list ()는 다음과 같이 정의됩니다.

class FactoryObject(object):
    # ... Code Here ...

    def list(self, **kwargs):
         if 'some_parameter' not in kwargs:
             raise Exception('some_parameter required argument')
         # ... code that uses kwargs['some_parameter']
         return True

그래서 내가 이번 명령을 실행하면 :

>>> orgunits.list()
Exception: some_parameter required argument
>>> orgunits.list('my_customer')
TypeError: list() takes exactly 1 argument (2 given)
>>> orgunits.list(some_parameter='my_customer')
True

따라서 다음에 오류가 표시되면 인수 목록에 매개 변수 이름을 추가하고 문제가 해결되는지 확인하십시오.

추가 정보:

사전 풀 연산자 (**)는 매개 변수 목록에서 일반적인 인수처럼 작동하지 않습니다. 위치 인수를 통과하면 이것이 목록의 유일한 인수 일 때 코드가 키워드 인수를 기대하기 때문에 오류가 발생합니다.

포장되지 않은 연산자는 임의의 키워드 인수를 수락하여 사전에서 사용할 수 있습니다.

다른 팁

파이썬이 지나가는 것이 될 수 있습니다 self 자동으로? 나는 또한 Python을 처음 접했기 때문에 Python이 언제 그렇게할지 확신 할 수 없지만 과거에는 나에게 약간의 혼란이 생겼습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top