Python类型错误:';MyException';对象不可调用
我有这样一个文件:Python类型错误:';MyException';对象不可调用,python,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):
# 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)
但有时,服务器会报告如下错误:
# 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'对象不可调用
但是堆栈跟踪非常奇怪:
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
我自己无法重现这个错误。我都试图禁用一个帐户并删除一个帐户。但这确实发生在我们的生产服务器上。我们找到了根案例:
try:
# some code
except auth.DeletedAccountError, auth.DisabledAccountError:
pass
太愚蠢了。我们找到了根案例:
try:
# some code
except auth.DeletedAccountError, auth.DisabledAccountError:
pass
太蠢了。我们使用多线程和多进程的
uwsgi
。这确实很奇怪。您确定代码的其余部分没有与您的问题相关的内容吗?这真的是完整的回溯吗?我们使用多线程和多进程的uwsgi
。这确实很奇怪。您确定代码的其余部分没有与您的问题相关的内容吗?这真的是完整的回溯吗?很好的谜题。显然,您使用的是Python2,因为Python3不再支持除ExceptionType、errorvar:之外的语法。为了大家的利益,你能花点时间解释一下发生了什么吗?很好的谜题。显然,您使用的是Python2,因为Python3不再支持除ExceptionType、errorvar:
之外的语法。为了其他人的利益,你能花点时间解释一下发生了什么吗?