首页 > 解决方案 > pjsua.error, error = 地址已在使用中

问题描述

我正在尝试在 python 中使用 PJSIP 模块拨打电话。对于 SIP 传输的设置,我正在做

trans_cfg = pj.TransportConfig()
# port for VoIP communication
trans_cfg.port = 5060
# local system address
trans_cfg.bound_addr = inputs.client_addr
transport = lib.create_transport(pj.TransportType.UDP,trans_cfg)

当我完成通话时,我将传输设置清除为transport = None.

我可以通过运行我的程序来调用用户。但是每次我单独重新启动我的电脑时,我在运行我的 python 程序时都会遇到错误

File "pjsuatrail_all.py", line 225, in <module>
   main()
File "pjsuatrail_all.py", line 169, in main
   transport = transport_setup()
File "pjsuatrail_all.py", line 54, in transport_setup
   transport = lib.create_transport(pj.TransportType.UDP,trans_cfg)
File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 2304, in 
   create_transport
   self._err_check("create_transport()", self, err)
File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 2723, in _err_check
   raise Error(op_name, obj, err_code, err_msg)
pjsua.Error: Object: Lib, operation=create_transport(), error=Address already in use
Exception AttributeError: "'NoneType' object has no attribute 'destroy'" in <bound method Lib.__del__ of <pjsua.Lib instance at 0x7f8a4bbb6170>> ignored

为此,我目前正在这样做

$sudo lsof -t -i:5060
>> 1137
$sudo kill 1137

然后我运行我的代码,它工作正常。通过错误的实例,我可以理解某处我没有正确关闭我的传输配置。任何人都可以在这方面提供帮助。 使用的参考代码

标签: pythonpjsiptelephony

解决方案


从您提供的输入中,可以理解这不是 pjsip 包装器的问题。传输配置看起来不错。

查看“create_transport”错误,程序无法创建连接,因为 5060 端口已被其他程序占用。

为此,您正在终止该进程,并且您可以运行该程序而不会出现任何错误。你说它只在重启时,所以在你的系统重启时,一些程序正在占用端口。

你可以这样尝试

sudo netstat -nlp|grep 5060

在你的情况下,它会像

第1137章

转到启动配置中的“程序名称”并进行修改,使其不会拾取端口。


推荐阅读