1

我目前正在尝试在 python 中使用pjsipapi pjsua,因此研究了这个 Hello World 示例:http ://trac.pjsip.org/repos/wiki/Python_SIP/Hello_World

我根据http://trac.pjsip.org/repos/wiki/Python_SIP/Accounts等复制了代码,集成了帐户配置。但是当我运行示例时,我得到以下输出:

Traceback (most recent call last):
    File "/home/dmeli/workspace/eit.cubiephone.sip_test/eit/cubiephone/sip_test/hello.py", line 48, in <module>
        acc = lib.create_account(acc_cfg)
    File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 2300, in create_account
        err, acc_id = _pjsua.acc_add(acc_config._cvt_to_pjsua(), set_default)
    File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 900, in _cvt_to_pjsua
        cfg.rtp_transport_cfg = self.rtp_transport_cfg._cvt_to_pjsua()
    AttributeError: '_pjsua.Transport_Config' object has no attribute '_cvt_to_pjsua'

因为我不是真正的 python 专家并且以前从未使用过 PJSIP,所以我无法真正找出错误。我也是,看起来它实际上是pjsippython包装器中的一个错误。但我知道什么?

代码:

lib = pj.Lib()
lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
transport = lib.create_transport(pj.TransportType.UDP)
lib.start()
acc_cfg = pj.AccountConfig("XXXXX", "XXXXXX", "XXXXXX")
acc_cfg.id = "sip:XXXXXXX@XXXXXXXX"
acc_cfg.reg_uri = "sip:XXXXXXXXX"
acc_cfg.proxy = [ "sip:XXXXXXXXX;lr" ]
acc = lib.create_account(acc_cfg)

# Make call
call = acc.make_call("XXXXXXXXXXX", MyCallCallback())

pjsua.py 中发生错误的行:

cfg.rtp_transport_cfg = self.rtp_transport_cfg._cvt_to_pjsua()

rtp_transport_cfg好像没有会员_cvt_to_pjsua()??)

4

1 回答 1

0

为了进一步正常工作,请查看他正在等待命令和结构的PJSIP api(pjsua.py)!

## start lib.
def start(self):
    try:
        self._start_lib()
        self._start_acc()
    except pj.Error:
        print "Error starting lib."



def _bind(self):
    try:
        t = pj.TransportConfig()
        t.bound_addr = '0.0.0.0'
        t.port = 5060 
        acc_transport = "udp" # depend if you need.
        if  acc_transport == "tcp":
            self.transport = self.lib.create_transport(pj.TransportType.TCP, t)
            # or this pj.TransportConfig(0) is creating random port ... 
            #self.transport = self.lib.create_transport(pj.TransportType.TCP, pj.TransportConfig(0))
        else:
            self.transport = self.lib.create_transport(pj.TransportType.UDP, t)
            #self.transport = self.lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
    except pj.Error:
        print "Error creating transport."

    #you need create callbacks for app, to work incoming calls, check on the server that returns the error code 200, and such a way your program will know that you are logged on correctly
    #from callback.acc_cb import acc_cb
    #self.acc_t = self.lib.create_account_for_transport(self.transport, cb=acc_cb())

def _start_lib(self):
    self.lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
    self.lib.start()
    self._bind()
    #codecs.load_codecs()


def _start_acc(self):
    #from callback.acc_cb import acc_cb
    try:
            proxy = "sip server ip" # or proxy = socket.gethostbyname(unicode("sip.serverdnsname.com")) is needed to import socket
            login = "Atrotygma" # real username
            password = "Atrotygma_password" # real username
            lib.create_account(acc_config=pj.AccountConfig(proxy, login, password))
    except Exception, e:
        print "Error creating account", e
于 2013-10-24T13:34:29.287 回答