奇怪的Python错误

奇怪的Python错误,python,django,Python,Django,此错误:cancel\u agreement()缺少1个必需的位置参数:“agreement\u id” 执行此方法时出现: def force_cancel(self): api = model_from_ref(self.processor.api) api.cancel_agreement(self.subscription_reference) # transaction.cancel_subscription() # runs in the callback

此错误:
cancel\u agreement()缺少1个必需的位置参数:“agreement\u id”

执行此方法时出现:

def force_cancel(self):
    api = model_from_ref(self.processor.api)
    api.cancel_agreement(self.subscription_reference)
    # transaction.cancel_subscription()  # runs in the callback
以下是
cancel\u agreement()
方法:

def cancel_agreement(self, agreement_id, is_upgrade=False):
    note = _("Upgrading billing plan") if is_upgrade else _("Canceling a service")
    r = self.session.post(self.server + '/v1/payments/billing-agreements/%s/cancel' % agreement_id,
                          data='{"note": "%s"}' % note,
                          headers={'content-type': 'application/json'})
    if r.status_code != requests.codes.ok:
        raise RuntimeError(_("Cannot cancel a billing agreement at PayPal. Please contact support."))
我不明白为什么会发生错误:它正在调用一个双参数函数(
api
self.subscription\u reference
),它的定义也是两个必需参数(
self
agreement\u id

遗憾的是,我无法展示完整的代码,因为我的业务合作伙伴反对发布开源软件。

应该是:

def force_cancel(self):
    klass = model_from_ref(self.processor.api)
    api = klass()
    api.cancel_agreement(self.subscription_reference)

cancel\u aggrement
应由
self
调用。非
api
。对吗?
api
和拥有该方法的类
force\u cancel
之间的关系是什么?什么是
type(api)
?是
api
存在
cancel\u agreement
的类的实例?@juanpa.arrivillaga
type(api)
PayPalAPI
。拥有
force_cancel
PayPalAPI
的类
事务
之间没有关系(除了一些方法调用问题代码中的其他方法)您可以通过修改
cancel\u agreement
进行调试,使其接受任意数量的位置参数:
def cancel\u argreement(*args,is\u upgrade=False):
。然后您可以
print()
或记录它接收的参数列表。这还将告诉您该方法的这个实现是否被调用,或者它是否在某个地方被覆盖或重载。(不过,当前错误消息的堆栈跟踪也应该告诉您是否如此。)