Python 即使设置了属性,也没有属性错误

Python 即使设置了属性,也没有属性错误,python,twisted,Python,Twisted,所以我有一个类,它扩展了两个类,下面是它的定义和_uinit _;: ChannelEventSocketProtocol的定义和初始化如下: class ChannelEventSocketProtocol(Freeswitch): def __init__(self, *args, **kwargs): self.channel_driver = None self.uuid = kwargs.pop('uuid', str(uuid4()))

所以我有一个类,它扩展了两个类,下面是它的定义和_uinit _;:

ChannelEventSocketProtocol的定义和初始化如下:

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 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以及回调和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_或_create_channel_驱动程序函数:

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.

某个地方忘记了实例化一个类

错误并不是告诉您ProspectEventSocketProtocol类的实例没有属性defer\u,直到\u通过身份验证。它告诉您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 回溯最近一次呼叫上次: 文件。/在中键入第12行的\u object\u error.py printError.arg AttributeError:类型对象“Test”没有属性“arg”
某个地方忘记了实例化一个类

错误并不是告诉您ProspectEventSocketProtocol类的实例没有属性defer\u,直到\u通过身份验证。它告诉您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 回溯最近一次呼叫上次: 文件。/在中键入第12行的\u object\u error.py printError.arg AttributeError:类型对象“Test”没有属性“arg”
尝试编辑ProspectEventSocketProtocol,使其看起来像并发布输出,您可能需要多次尝试链接;Pastebin似乎有点过载:。相同的错误仍然存在,并且没有打印任何内容,因此看起来没有删除任何属性。:/尝试编辑ProspectEventSocketProtocol,使其看起来像并发布输出,您可能需要多次尝试链接;Pastebin似乎有点过载:。相同的错误仍然存在,并且没有打印任何内容,因此看起来没有删除任何属性。:/