Hi
I'm following pjsua2 book documentation to create a SIP client using python3.6 (from here: https://www.pjsip.org/docs/book-latest/html/index.html)
I compiled myself pjsip 2.9 (tried too 2.8 and current code) but I cannot run the code properly.
The test.py code is:
test.py --------------------------------------------------------------------------------
import time
import pjsua2 as pj
# uri = "sip:test@xxxxxxxxx"
# reguri = "sip:pjsip.org"
# name = "test"
# passwd = "pwtest"
uri = "sip:client1@localhost"
reguri = "sip:localhost"
name = "client1"
passwd = "1234"
port = 5061
# Subclass to extend the Account and get notifications etc.
class Account(pj.Account):
def onRegState(self, prm):
print("***OnRegState: " + prm.reason)
# pjsua2 test function
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig()
sipTpConfig.port = port
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
# Start the library
ep.libStart()
acfg = pj.AccountConfig()
acfg.idUri = uri
acfg.regConfig.registrarUri = reguri
cred = pj.AuthCredInfo("digest", "*", name, 0, passwd)
acfg.sipConfig.authCreds.append( cred )
# Create the account
acc = Account()
acc.create(acfg)
# Here we don't have anything else to do..
time.sleep(10)
# Destroy the library
ep.libDestroy()
#
# main()
#
if __name__ == "__main__":
pjsua2_test()
--------------------------------------------------------------------------------
The client log generated is:
test_python_code.log --------------------------------------------------------------------------------
16:21:21.802 os_core_unix.c !pjlib 2.9 for POSIX initialized
16:21:21.803 sip_endpoint.c .Creating endpoint instance...
16:21:21.803 pjlib .select() I/O Queue created (0x557b5306daa0)
16:21:21.803 sip_endpoint.c .Module "mod-msg-print" registered
16:21:21.803 sip_transport.c .Transport manager created.
16:21:21.803 pjsua_core.c .PJSUA state changed: NULL --> CREATED
16:21:21.803 sip_endpoint.c .Module "mod-pjsua-log" registered
16:21:21.803 sip_endpoint.c .Module "mod-tsx-layer" registered
16:21:21.803 sip_endpoint.c .Module "mod-stateful-util" registered
16:21:21.803 sip_endpoint.c .Module "mod-ua" registered
16:21:21.803 sip_endpoint.c .Module "mod-100rel" registered
16:21:21.803 sip_endpoint.c .Module "mod-pjsua" registered
16:21:21.803 sip_endpoint.c .Module "mod-invite" registered
16:21:22.012 alsa_dev.c ..ALSA driver found 32 devices
16:21:22.012 alsa_dev.c ..ALSA initialized
16:21:22.012 pjlib ..select() I/O Queue created (0x557b531f0fb8)
16:21:22.017 sip_endpoint.c .Module "mod-evsub" registered
16:21:22.017 sip_endpoint.c .Module "mod-presence" registered
16:21:22.017 sip_endpoint.c .Module "mod-mwi" registered
16:21:22.017 sip_endpoint.c .Module "mod-refer" registered
16:21:22.017 sip_endpoint.c .Module "mod-pjsua-pres" registered
16:21:22.017 sip_endpoint.c .Module "mod-pjsua-im" registered
16:21:22.017 sip_endpoint.c .Module "mod-pjsua-options" registered
16:21:22.017 pjsua_core.c .1 SIP worker threads created
16:21:22.017 pjsua_core.c .pjsua version 2.9 for Linux-5.0.0.32/x86_64/glibc-2.27 initialized
16:21:22.017 pjsua_core.c .PJSUA state changed: CREATED --> INIT
16:21:22.018 pjsua_core.c SIP UDP socket reachable at 192.168.4.115:5061
16:21:22.018 udp0x557b53205750 SIP UDP transport started, published address is 192.168.4.115:5061
16:21:22.018 pjsua_core.c PJSUA state changed: INIT --> STARTING
16:21:22.018 sip_endpoint.c .Module "mod-unsolicited-mwi" registered
16:21:22.018 pjsua_core.c .PJSUA state changed: STARTING --> RUNNING
16:21:22.018 pjsua_acc.c Adding account: id=sip:client1@localhost
16:21:22.018 pjsua_acc.c .Account sip:client1@localhost added with id 0
16:21:22.018 pjsua_acc.c .Acc 0: setting registration..
16:21:22.018 pjsua_core.c ...TX 496 bytes Request msg REGISTER/cseq=40051 (tdta0x557b531cde28) to UDP 127.0.0.1:5060:
REGISTER sip:localhost SIP/2.0
Via: SIP/2.0/UDP 192.168.4.115:5061;rport;branch=z9hG4bKPj65e59469-4dca-4374-ad7b-427e274941b3
Max-Forwards: 70
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40051 REGISTER
Contact: <sip:client1@192.168.4.115:5061;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0
--end msg--
16:21:22.018 pjsua_acc.c ..Acc 0: Registration sent
16:21:22.018 pjsua_core.c .RX 577 bytes Response msg 401/REGISTER/cseq=40051 (rdata0x557b531c9fa8) from UDP 127.0.0.1:5060:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.4.115:5061;branch=z9hG4bKPj65e59469-4dca-4374-ad7b-427e274941b3;received=127.0.0.1;rport=5061
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>;tag=as72f046ae
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40051 REGISTER
Server: Asterisk PBX 14.3.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="5a826d8a"
Content-Length: 0
--end msg--
16:21:22.018 pjsua_acc.c ....IP address change detected for account 0 (192.168.4.115:5061 --> 127.0.0.1:5061). Updating registration (using method 4)
16:21:22.019 pjsua_core.c ....TX 647 bytes Request msg REGISTER/cseq=40052 (tdta0x557b531cde28) to UDP 127.0.0.1:5060:
REGISTER sip:localhost SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5061;rport;branch=z9hG4bKPj78ce9b35-b46f-4714-b185-4b8197e19fc1
Max-Forwards: 70
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40052 REGISTER
Contact: <sip:client1@127.0.0.1:5061;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username="client1", realm="asterisk", nonce="5a826d8a", uri="sip:localhost", response="012a7639a11e8780266209114ba682e4", algorithm=MD5
Content-Length: 0
--end msg--
16:21:22.019 pjsua_core.c .RX 592 bytes Response msg 200/REGISTER/cseq=40052 (rdata0x7fc634008e88) from UDP 127.0.0.1:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 127.0.0.1:5061;branch=z9hG4bKPj78ce9b35-b46f-4714-b185-4b8197e19fc1;received=127.0.0.1;rport=5061
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>;tag=as72f046ae
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40052 REGISTER
Server: Asterisk PBX 14.3.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Expires: 300
Contact: <sip:client1@127.0.0.1:5061;ob>;expires=300
Date: Wed, 23 Oct 2019 14:21:22 GMT
Content-Length: 0
--end msg--
16:21:22.019 pjsua_acc.c ....SIP outbound status for acc 0 is not active
16:21:22.019 pjsua_acc.c ....sip:client1@localhost: registration success, status=200 (OK), will re-register in 300 seconds
16:21:22.019 pjsua_acc.c ....Keep-alive timer started for acc 0, destination:127.0.0.1:5060:15, interval:0s
[1] 4673 segmentation fault (core dumped) python test.py
16:21:21.803 sip_endpoint.c .Creating endpoint instance...
16:21:21.803 pjlib .select() I/O Queue created (0x557b5306daa0)
16:21:21.803 sip_endpoint.c .Module "mod-msg-print" registered
16:21:21.803 sip_transport.c .Transport manager created.
16:21:21.803 pjsua_core.c .PJSUA state changed: NULL --> CREATED
16:21:21.803 sip_endpoint.c .Module "mod-pjsua-log" registered
16:21:21.803 sip_endpoint.c .Module "mod-tsx-layer" registered
16:21:21.803 sip_endpoint.c .Module "mod-stateful-util" registered
16:21:21.803 sip_endpoint.c .Module "mod-ua" registered
16:21:21.803 sip_endpoint.c .Module "mod-100rel" registered
16:21:21.803 sip_endpoint.c .Module "mod-pjsua" registered
16:21:21.803 sip_endpoint.c .Module "mod-invite" registered
16:21:22.012 alsa_dev.c ..ALSA driver found 32 devices
16:21:22.012 alsa_dev.c ..ALSA initialized
16:21:22.012 pjlib ..select() I/O Queue created (0x557b531f0fb8)
16:21:22.017 sip_endpoint.c .Module "mod-evsub" registered
16:21:22.017 sip_endpoint.c .Module "mod-presence" registered
16:21:22.017 sip_endpoint.c .Module "mod-mwi" registered
16:21:22.017 sip_endpoint.c .Module "mod-refer" registered
16:21:22.017 sip_endpoint.c .Module "mod-pjsua-pres" registered
16:21:22.017 sip_endpoint.c .Module "mod-pjsua-im" registered
16:21:22.017 sip_endpoint.c .Module "mod-pjsua-options" registered
16:21:22.017 pjsua_core.c .1 SIP worker threads created
16:21:22.017 pjsua_core.c .pjsua version 2.9 for Linux-5.0.0.32/x86_64/glibc-2.27 initialized
16:21:22.017 pjsua_core.c .PJSUA state changed: CREATED --> INIT
16:21:22.018 pjsua_core.c SIP UDP socket reachable at 192.168.4.115:5061
16:21:22.018 udp0x557b53205750 SIP UDP transport started, published address is 192.168.4.115:5061
16:21:22.018 pjsua_core.c PJSUA state changed: INIT --> STARTING
16:21:22.018 sip_endpoint.c .Module "mod-unsolicited-mwi" registered
16:21:22.018 pjsua_core.c .PJSUA state changed: STARTING --> RUNNING
16:21:22.018 pjsua_acc.c Adding account: id=sip:client1@localhost
16:21:22.018 pjsua_acc.c .Account sip:client1@localhost added with id 0
16:21:22.018 pjsua_acc.c .Acc 0: setting registration..
16:21:22.018 pjsua_core.c ...TX 496 bytes Request msg REGISTER/cseq=40051 (tdta0x557b531cde28) to UDP 127.0.0.1:5060:
REGISTER sip:localhost SIP/2.0
Via: SIP/2.0/UDP 192.168.4.115:5061;rport;branch=z9hG4bKPj65e59469-4dca-4374-ad7b-427e274941b3
Max-Forwards: 70
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40051 REGISTER
Contact: <sip:client1@192.168.4.115:5061;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0
--end msg--
16:21:22.018 pjsua_acc.c ..Acc 0: Registration sent
16:21:22.018 pjsua_core.c .RX 577 bytes Response msg 401/REGISTER/cseq=40051 (rdata0x557b531c9fa8) from UDP 127.0.0.1:5060:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.4.115:5061;branch=z9hG4bKPj65e59469-4dca-4374-ad7b-427e274941b3;received=127.0.0.1;rport=5061
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>;tag=as72f046ae
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40051 REGISTER
Server: Asterisk PBX 14.3.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="5a826d8a"
Content-Length: 0
--end msg--
16:21:22.018 pjsua_acc.c ....IP address change detected for account 0 (192.168.4.115:5061 --> 127.0.0.1:5061). Updating registration (using method 4)
16:21:22.019 pjsua_core.c ....TX 647 bytes Request msg REGISTER/cseq=40052 (tdta0x557b531cde28) to UDP 127.0.0.1:5060:
REGISTER sip:localhost SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5061;rport;branch=z9hG4bKPj78ce9b35-b46f-4714-b185-4b8197e19fc1
Max-Forwards: 70
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40052 REGISTER
Contact: <sip:client1@127.0.0.1:5061;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username="client1", realm="asterisk", nonce="5a826d8a", uri="sip:localhost", response="012a7639a11e8780266209114ba682e4", algorithm=MD5
Content-Length: 0
--end msg--
16:21:22.019 pjsua_core.c .RX 592 bytes Response msg 200/REGISTER/cseq=40052 (rdata0x7fc634008e88) from UDP 127.0.0.1:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 127.0.0.1:5061;branch=z9hG4bKPj78ce9b35-b46f-4714-b185-4b8197e19fc1;received=127.0.0.1;rport=5061
From: <sip:client1@localhost>;tag=20b20212-a3ea-4a69-aa2c-2722fc3d8c82
To: <sip:client1@localhost>;tag=as72f046ae
Call-ID: f5ac12e4-efdc-4796-82da-bd0d6ea18a68
CSeq: 40052 REGISTER
Server: Asterisk PBX 14.3.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Expires: 300
Contact: <sip:client1@127.0.0.1:5061;ob>;expires=300
Date: Wed, 23 Oct 2019 14:21:22 GMT
Content-Length: 0
--end msg--
16:21:22.019 pjsua_acc.c ....SIP outbound status for acc 0 is not active
16:21:22.019 pjsua_acc.c ....sip:client1@localhost: registration success, status=200 (OK), will re-register in 300 seconds
16:21:22.019 pjsua_acc.c ....Keep-alive timer started for acc 0, destination:127.0.0.1:5060:15, interval:0s
[1] 4673 segmentation fault (core dumped) python test.py
--------------------------------------------------------------------------------
It
seems it is failing when parsing the registration callback, but in my
code it seems it all ok. The code fail too with invalid credential and
only if asterisk server is running, if not is running, register callback
(this log line no appear: 16:21:22.019 pjsua_acc.c
....sip:client1@localhost: registration success, status=200 (OK), will
re-register in 300 seconds) and it does not crash.
The problem happens at C level. The asterisk server is registering properly the user:
asterisk.log ----------------------------------------------------------------
Asterisk Ready.
*CLI> -- Registered SIP 'client1' at 127.0.0.1:5061
--------------------------------------------------------------------------------
How can I solve this?
Thanks.
_________________________________________________________
Víctor Goñi Sanz
Tecnología | Biometría de Voz
Veridas Digital Authentication Solutions S.L.
Polígono Industrial Talluntxe II, Calle M-10
31192, Tajonar, Navarra, SPAIN
Map: Veridas
Web: www.veri-das.com
Email: vgoni@xxxxxxxxxxxx
Phone: +34 948 24 62 95
Mobile: +34 622 226 276
_______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@xxxxxxxxxxxxxxx http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org