我正在将python模块用于pjsua并尝试注册到PBX。

这是代码:

import sys
import pjsua as pj
import threading


def log_cb(level, str, len)
    print str,

class MyAccountCallback(pj.AccountCallback)
    sem = None

    def __init__(self, account)
        pj.AccountCallback.__init__(self, account)

    def wait(self)
        self.sem = threading.Semaphore(0)
        self.sem.acquire()

    def on_reg_state(self)
        if self.sem
            if self.account.info().reg_status = 200
                self.sem.release()

lib = pj.Lib()

try
    lib.init(log_cfg = pj.LogConfig(level=4, callback=log_cb))
    lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5060))
    lib.start()

    acc = lib.create_account(pj.AccountConfig("181.21.200.109:5060", "561123", "admin"))

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()

    print n
    print Registration complete, status=, acc.info().reg_status,
          ( + acc.info().reg_reason + )
    print nPress ENTER to quit
    sys.stdin.readline()

    lib.destroy()
    lib = None

except pj.Error, e
    print Exception  + str(e)
    lib.destroy()


PBX IP是181.21.200.109,我要注册的号码是123456,关于密码-我只输入了123(我认为PBX不需要密码)。

我从PBX收到一个禁止SIP 403 SIP数据包(错误身份验证)。

为了进行比较,我查看了另一个来自成功注册的SIP客户端的注册数据包。 (集团电话发回OPTIONS数据包)。

这些是数据包:

该数据包获得FORBIDEN(错误身份验证)响应(失败)

REGISTER sip:181.21.200.109:5060 SIP/2.0

Via: SIP/2.0/UDP 181.21.200.50:51117;rport;branch=z9hG4bKPj36c48c6ff87b47ac86c9036e0acbaed4 (Different)

Route: <sip:181.21.200.109:5060;lr> (Different)

Max-Forwards: 70

From: <sip:[email protected]>;tag=10a3290c7748480c9c0808366ae0c840 (Different)

To: <sip:[email protected]> (Different)

Call-ID: 94f280c9cfcf41539b500ff39582a1ef

CSeq: 21606 REGISTER

User-Agent: pjsip python

Contact: <sip:[email protected]:51117;ob> (Different)

Expires: 300

Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS - (Different Options)

Authorization: Digest username="561123", realm="asterisk", nonce="21f4ad6b", uri="sip:181.21.200.109:5060", response="62a339057d2b4e3fed4d368ff94f6d46", algorithm=MD5

Content-Length:  0


该数据包得到OPTIONS响应(成功)

REGISTER sip:181.21.200.109:5060 SIP/2.0

Via: SIP/2.0/UDP 181.21.200.150;rport;branch=z9hG4bK4H5Z6Z2myFUNr

Max-Forwards: 70

From: <sip:[email protected]:5060>;tag=307m6Zy8cj7pa

To: <sip:[email protected]:5060>

Call-ID: f3ce9234-40e3-1233-a783-5c6b32d1a9b5

CSeq: 3 REGISTER

Contact: <sip:[email protected]>

User-Agent: sofia-sip/1.12.11

Allow: REGISTER, INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, SUBSCRIBE, REFER, UPDATE, INFO

Supported: timer, 100rel, path

Authorization: Digest username="561123", realm="asterisk", nonce="7625cf17", algorithm=MD5, uri="sip:181.21.200.109:5060", response="dca3173b2159f812481ca0c96b10a751"

Content-Length: 0


有人知道我为什么得到禁止的回复吗?我的代码有问题吗?

提前感谢

最佳答案

您的PABX确实需要这些帐户的密码(否则我们将看不到现时,响应和授权标头本身),因此请确保密码有效。
如果未找到帐户(配置:alwaysauthreject = yes),并且您尝试从python和独立客户端注册其他扩展名时,星号也可能拒绝403注册(配置:alwaysauthreject = yes)。

最好使用相同的分机进行比较(但不要尝试同时将两个软件电话注册到同一分机)。

10-08 08:06