方法需要2个参数(给出3个)

时间:2014-01-08 17:27:16

标签: python python-2.7 self

我是python的新手并且遇到以下代码的问题,我知道它与self关键字有关,但我不确定我做错了什么。

主要代码:

user_operation = UserOperations(headers)

user = user_operation.get_user(arguments['source'],arguments['id'])

user_operations:

class UserOperations(object):
    def __init__(self, headers):
        self.headers = headers

    def get_user(self, account_id, user_id):

        #Get user
        user = requests.get(api_root + "/accounts/" + account_id + "/users/" + user_id, headers=headers)

        #Throw exception if non-200 response
        user.raise_for_status()

        print "\nGet User " + user_id + ": " + user.text

        #Check user exists
        if user.json()['Data'] is None:
            return None

        #Return user
        return user.json()['Data']

错误:

Traceback (most recent call last):
  File "py-front.py", line 117, in <module>
    user = user_operation.get_user(arguments['<source>'],arguments['<id>'])
TypeError: get_user() takes exactly 2 arguments (3 given)

任何帮助将不胜感激!

0 个答案:

没有答案