即使设置了属性也没有属性错误
No attribute error even when the attribute is set
所以我有一个 class 扩展了两个 classes 深,这是它的定义和 __init__()
:
class ProspectEventSocketProtocol(ChannelEventSocketProtocol):
def __init__(self, *args, **kwargs):
super(ProspectEventSocketProtocol, self).__init__(*args, **kwargs)
self.channel_info = None
self.rep_uuid = None
self.manual_dial = None
self.datetime_setup = timezone.now()
self.datetime_answered = None
self.defer_until_answered = defer.Deferred()
self.defer_until_originated = defer.Deferred()
self.defer_until_finished = defer.Deferred()
ChannelEventSocketProtocol 的定义和 __init__()
在这里:
class ChannelEventSocketProtocol(Freeswitch):
def __init__(self, *args, **kwargs):
self.channel_driver = None
self.uuid = kwargs.pop('uuid', str(uuid4()))
self._call_driver = kwargs.pop('call_driver', None)
super(ChannelEventSocketProtocol, self).__init__(*args, **kwargs)
Freeswitch class 的定义和 __init__()
在这里:
class Freeswitch(client.EventSocketProtocol, TwistedLoggingMixin):
def __init__(self, *args, **kwargs):
self.jobs = {}
self.defer_until_authenticated = defer.Deferred() # This is the problem
client.EventSocketProtocol.__init__(self, *args, **kwargs)
TwistedLoggingMixin.__init__(self)
即使我知道这是 运行 并且正在设置 defer_until_authenticated 以及 callback
和 errback
,当我调用它时:
live_call = yield self._create_client_dial_live_call(client_dial.cid, client_dial.campaign)
pchannel = yield self.realm.get_or_create_channel_driver(live_call.uuid, 'prospect')
# ...
client_dial.prospect_channel = pchannel
yield pchannel.freeswitch_protocol.defer_until_authenticated # This is the problem here!
我收到错误:
type object 'ProspectEventSocketProtocol' has no attribute 'defer_until_authenticated'
我不知道为什么我无法再次获得该属性。我知道它正在设置,但我不知道它去了哪里......或者它会发生什么。我已经搜索了错误,我不知道这个地方发生了什么。
仅供参考,这里是 _create_client_dial_live_call()
和 get_or_create_channel_driver()
函数:
def _create_client_dial_live_call():
# ...
p, created = Prospect.objects.get_or_create_client_dial_prospect(campaign, cid_num)
# ...
live_call = LiveCall(prospect=p, campaign=campaign.slug)
live_call.channel_vars_dict = chan_vars
live_call.save()
# ...
def get_or_create_channel_driver()
# The code is kind of confusing with even more context,
# it basically either gets the existing ProspectChannel
# object or creates a new one and then returns it.
某处某处忘记实例化 class。
错误不是告诉您 class ProspectEventSocketProtocol
的实例没有属性 defer_until_authenticated
。它告诉你 class ProspectEventSocketProtocol
本身没有这样的属性。
换句话说,你很可能在写类似
的东西
pchannel.freeswitch_protocol = ProspectEventSocketProtocol
当你想要的时候
pchannel.freeswitch_protocol = ProspectEventSocketProtocol(...)
相反。
这是一个快速演示脚本,可重现您看到的错误消息:
#!/usr/bin/env python3
class Test(object):
def __init__(self):
self.arg = "1234"
correct = Test()
print(correct.arg)
wrong = Test
print(wrong.arg)
当我 运行 它时,我得到以下输出:
1234
Traceback (most recent call last):
File "./type_object_error.py", line 12, in <module>
print(wrong.arg)
AttributeError: type object 'Test' has no attribute 'arg'
所以我有一个 class 扩展了两个 classes 深,这是它的定义和 __init__()
:
class ProspectEventSocketProtocol(ChannelEventSocketProtocol):
def __init__(self, *args, **kwargs):
super(ProspectEventSocketProtocol, self).__init__(*args, **kwargs)
self.channel_info = None
self.rep_uuid = None
self.manual_dial = None
self.datetime_setup = timezone.now()
self.datetime_answered = None
self.defer_until_answered = defer.Deferred()
self.defer_until_originated = defer.Deferred()
self.defer_until_finished = defer.Deferred()
ChannelEventSocketProtocol 的定义和 __init__()
在这里:
class ChannelEventSocketProtocol(Freeswitch):
def __init__(self, *args, **kwargs):
self.channel_driver = None
self.uuid = kwargs.pop('uuid', str(uuid4()))
self._call_driver = kwargs.pop('call_driver', None)
super(ChannelEventSocketProtocol, self).__init__(*args, **kwargs)
Freeswitch class 的定义和 __init__()
在这里:
class Freeswitch(client.EventSocketProtocol, TwistedLoggingMixin):
def __init__(self, *args, **kwargs):
self.jobs = {}
self.defer_until_authenticated = defer.Deferred() # This is the problem
client.EventSocketProtocol.__init__(self, *args, **kwargs)
TwistedLoggingMixin.__init__(self)
即使我知道这是 运行 并且正在设置 defer_until_authenticated 以及 callback
和 errback
,当我调用它时:
live_call = yield self._create_client_dial_live_call(client_dial.cid, client_dial.campaign)
pchannel = yield self.realm.get_or_create_channel_driver(live_call.uuid, 'prospect')
# ...
client_dial.prospect_channel = pchannel
yield pchannel.freeswitch_protocol.defer_until_authenticated # This is the problem here!
我收到错误:
type object 'ProspectEventSocketProtocol' has no attribute 'defer_until_authenticated'
我不知道为什么我无法再次获得该属性。我知道它正在设置,但我不知道它去了哪里......或者它会发生什么。我已经搜索了错误,我不知道这个地方发生了什么。
仅供参考,这里是 _create_client_dial_live_call()
和 get_or_create_channel_driver()
函数:
def _create_client_dial_live_call():
# ...
p, created = Prospect.objects.get_or_create_client_dial_prospect(campaign, cid_num)
# ...
live_call = LiveCall(prospect=p, campaign=campaign.slug)
live_call.channel_vars_dict = chan_vars
live_call.save()
# ...
def get_or_create_channel_driver()
# The code is kind of confusing with even more context,
# it basically either gets the existing ProspectChannel
# object or creates a new one and then returns it.
某处某处忘记实例化 class。
错误不是告诉您 class ProspectEventSocketProtocol
的实例没有属性 defer_until_authenticated
。它告诉你 class ProspectEventSocketProtocol
本身没有这样的属性。
换句话说,你很可能在写类似
的东西pchannel.freeswitch_protocol = ProspectEventSocketProtocol
当你想要的时候
pchannel.freeswitch_protocol = ProspectEventSocketProtocol(...)
相反。
这是一个快速演示脚本,可重现您看到的错误消息:
#!/usr/bin/env python3
class Test(object):
def __init__(self):
self.arg = "1234"
correct = Test()
print(correct.arg)
wrong = Test
print(wrong.arg)
当我 运行 它时,我得到以下输出:
1234
Traceback (most recent call last):
File "./type_object_error.py", line 12, in <module>
print(wrong.arg)
AttributeError: type object 'Test' has no attribute 'arg'