You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PJSUA2 Python脚本无法接听来电,自动返回603拒绝

PJSUA2 Python脚本无法接听来电,返回603 Decline问题求助

我使用PJSUA2 Python脚本无法接听来电,已尽可能简化脚本(基于官方helloworld示例及来电接收文档),拨打关联号码时呼叫立即失败并返回603 Decline。我已排除GC(持久化PJSua对象)、音频设备(使用setNullDev())、NAT(部署在Vultr直连IPv4服务器)等常见问题,部署环境为Ubuntu 22.04,以下是我的脚本及部署脚本,恳请技术支持。

Python脚本

import pjsua2 as pj
import time


class MyAccount(pj.Account):
    def onRegState(self, prm):
        print("***OnRegState: " + prm.reason)

    def onIncomingCall(self, iprm):
        call = MyCall(self, iprm.callId)
        prm = pj.CallOpParam()
        prm.statusCode = 200
        call.answer(prm)


class MyCall(pj.Call):
    def __init__(self, account, call_id):
        pj.Call.__init__(self, account, call_id)


def pjsua2_test():
    # Create and initialize the library
    ep_cfg = pj.EpConfig()
    ep = pj.Endpoint()
    ep.libCreate()
    ep.libInit(ep_cfg)
    ep.audDevManager().setNullDev()

    # Create SIP transport. Error handling sample is shown
    sipTpConfig = pj.TransportConfig()
    sipTpConfig.port = 5060
    ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)

    # Start the library
    ep.libStart()

    # Account configuration
    acfg = pj.AccountConfig()
    acfg.idUri = "sip:test@sip.pjsip.org";
    acfg.regConfig.registrarUri = "sip:sip.pjsip.org";
    cred = pj.AuthCredInfo("digest", "*", "test", 0, "pwtest");
    acfg.sipConfig.authCreds.append( cred );
    acfg.sipConfig.authCreds.append(cred)

    # Create the account
    acc = MyAccount()
    acc.create(acfg)

    return ep, acc  # Return the endpoint to keep it alive


if __name__ == "__main__":
    ep, acc = pjsua2_test()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Exiting...")
    finally:
        ep.libDestroy()

部署脚本

apt-get update && apt-get install -y build-essential libssl-dev libasound2-dev wget python3 python3-dev automake autoconf libtool libpcre2-dev bison && apt install -y python3-setuptools && cd /usr/src && wget https://github.com/swig/swig/archive/refs/tags/v4.2.1.tar.gz && tar -xvf v4.2.1.tar.gz && cd swig-4.2.1 && ./autogen.sh && ./configure && make && make install && cd /usr/src && wget https://github.com/pjsip/pjproject/archive/refs/tags/2.14.1.tar.gz && tar -xvf 2.14.1.tar.gz && cd pjproject* && ./configure CFLAGS="-fPIC" && make dep && make && make install && cd /usr/src/pjproject*/pjsip-apps/src/swig/python && make && make install && python3 setup.py install

内容的提问来源于stack exchange,提问作者Rick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 06:23:13