pjsua - 获得403禁止(认证错误)

时间:2015-02-23 11:01:50

标签: python sip pjsip

我正在使用pjsua的python模块并尝试注册到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(我不是&#39) ;认为PBX需要密码)。

我从PBX获得SIP禁止的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:561123@181.21.200.109>;tag=10a3290c7748480c9c0808366ae0c840 (Different)

To: <sip:561123@181.21.200.109> (Different)

Call-ID: 94f280c9cfcf41539b500ff39582a1ef

CSeq: 21606 REGISTER

User-Agent: pjsip python

Contact: <sip:561123@181.21.200.50: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:561123@181.21.200.109:5060>;tag=307m6Zy8cj7pa

To: <sip:561123@181.21.200.109:5060>

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

CSeq: 3 REGISTER

Contact: <sip:561123@181.21.200.150>

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

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

感谢adcance

1 个答案:

答案 0 :(得分:1)

您的PABX 确实需要这些帐户的密码(否则我们不会看到nonce,响应和授权标头本身),因此请确保密码有效。 如果找不到帐户,Asterisk也可以拒绝注册403(配置:alwaysauthreject = yes),并且您的日志没有说明,因为您尝试从python和独立客户端注册不同的扩展名。

最好使用相同的扩展名进行比较(但不要尝试同时注册两个软电话到相同的扩展名)。