Python TypeError:“MyException”对象不是callab

2024-06-02 20:29:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样一个文件:

# filename: auth.py

class DisabledAccountError(Exception):
    def __init__(self, uid):
        self.uid = uid

    def __str__(self):
        return repr(self.uid)


class DeletedAccountError(Exception):
    def __init__(self, uid):
        self.uid = uid

    def __str__(self):
        return repr(self.uid)

def login_validation(account): 
    if login_info.status == OBJECT_STATUS_DISABLED:
        raise DisabledAccountError(login_info.uid) # this is line 426

    if login_info.status == OBJECT_STATUS_DELETED:
        raise DeletedAccountError(login_info.uid)

但有时,服务器会报告如下错误:

TypeError: 'DeletedAccountError' object is not callable

但是堆叠的痕迹很奇怪:

TypeError: 'DeletedAccountError' object is not callable
  File "xxxxxx.py", line 104, in login_validation
    login_info = auth.login_validation(account)
  File "auth.py", line 426, in login_validation
    raise DisabledAccountError(login_info.uid)

这个错误是怎么发生的?你知道吗

为什么错误是DeletedAccountError,而堆栈跟踪是DisabledAccountError?你知道吗

我自己无法再现这个错误。我都试图禁用一个帐户并删除一个帐户。但它确实发生在我们的生产服务器上。你知道吗


Tags: pyselfinfoauthuidisdef错误