Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyVoIP fails to register to Asterisk #263

Open
ivanvujisic opened this issue Jun 14, 2024 · 5 comments
Open

PyVoIP fails to register to Asterisk #263

ivanvujisic opened this issue Jun 14, 2024 · 5 comments

Comments

@ivanvujisic
Copy link

I tried PyVoIP basic example:

from pyVoIP.VoIP import VoIPPhone, InvalidStateError

def answer(call):
try:
call.answer()
call.hangup()
except InvalidStateError:
pass

if name == "main":
phone = VoIPPhone('******', '5060', '2005', '', myIP='127.0.0.1', callCallback=answer)
phone.start()
input('Press enter to disable the phone')
phone.stop()

[root@vujisic pyvoip]# python3.6 -V
Python 3.6.6
[root@vujisic pyvoip]# pip3.6 -V
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
[root@vujisic pyvoip]# python3.6 phone-auto-answer-hangup.py
SIPClient.gen_tag called from SIPClient.init start NSD False
SIPClient.gen_urn_uuid called from SIPClient.init start
VoIPPhone.start called from start
SIPClient.start called from VoIPPhone.start start IP 127.0.0.1 Port 5060
SIPClient.register called from SIPClient.start start
SIPClient.gen_first_response called from SIPClient.register start
SIPClient.gen_branch called from SIPClient.gen_first_response start
SIPClient.gen_call_id called from SIPClient.gen_first_response start
SIPClient.send_message called from SIPClient.register --> message sever 67.220.85.61 port 5060

REGISTER sip:67.220.85.61 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK9340ee15d0974bf2bee08fb90;rport
From: "2005" sip:2005@67.220.85.61;tag=9dbfdbf6
To: "2005" sip:2005@67.220.85.61
Call-ID: 6b86b273ff34fce19d6b804eff5a3f57@127.0.0.1:5060
CSeq: 1 REGISTER
Contact: sip:127.0.0.1:5060;transport=UDP;+sip.instance="urn:uuid:571D34F4-B3BB-45C7-9199-C1BF5F3D2B7D"
Allow: INVITE, ACK, BYE, CANCEL, NOTIFY
Max-Forwards: 70
Allow-Events: org.3gpp.nwinitdereg
User-Agent: pyVoIP 1.6.1
Expires: 120
Content-Length: 0


SIPClient.stop called from VoIPPhone.start start
SIPClient._close_sockets called from SIPClient.stop start
Traceback (most recent call last):
File "phone-auto-answer-hangup.py", line 13, in
phone.start()
File "/usr/local/lib/python3.6/site-packages/pyVoIP/VoIP.py", line 519, in start
self.sip.start()
File "/usr/local/lib/python3.6/site-packages/pyVoIP/SIP.py", line 924, in start
self.register()
File "/usr/local/lib/python3.6/site-packages/pyVoIP/SIP.py", line 1484, in register
self.send_message(firstRequest)
File "/usr/local/lib/python3.6/site-packages/pyVoIP/SIP.py", line 810, in send_message
self.out.sendto(message.encode('utf8'), ((self.proxy if self.proxy else self.server), self.port))
TypeError: an integer is required (got type str)

This line: Via: SIP/2.0/UDP 127.0.0.1:5060 i.e. 127.0.0.1 doesn't matter since I tried 0.0.0.0, {server public ip address}

@ivanvujisic
Copy link
Author

now I tried with myIP='192.168.1.73' according to:

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether dc:21:48:f9:da:cb brd ff:ff:ff:ff:ff:ff
altname wlp0s20f3
inet 192.168.1.73/24 brd 192.168.1.255 scope global dynamic noprefixroute wlo1
valid_lft 68067sec preferred_lft 68067sec
inet6 fe80::d962:45b2:f8e0:b60/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:16:37:55:ed brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever

so this is sip dialog I got from sngrep 5 times:

REGISTER sip:67.220.85.61 SIP/2.0
Via: SIP/2.0/UDP 87.116.135.135:13135;branch=z9hG4bKf420a2e9491e442985b6f10bd;rport
From: "2005" sip:2005@67.220.85.61;tag=d2678e49
To: "2005" sip:2005@67.220.85.61
Call-ID: d4735e3a265e16eee03f59718b9b5d03@192.168.1.73:5060
CSeq: 2 REGISTER
Contact: sip:2005@87.116.135.135:13135;transport=UDP;+sip.instance="urn:uuid:5650A020-6155-484E-92D8-AED33CF3B153"
Allow: INVITE, ACK, BYE, CANCEL
Max-Forwards: 70
Allow-Events: org.3gpp.nwinitdereg
User-Agent: pyVoIP 1.6.8
Expires: 120
Content-Length: 0

SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 87.116.135.135:13135;branch=z9hG4bKf420a2e9491e442985b6f10bd;received=87.116.135.135;rport=13135
From: "2005" sip:2005@67.220.85.61;tag=d2678e49
To: "2005" sip:2005@67.220.85.61;tag=as5fcf3ad9
Call-ID: d4735e3a265e16eee03f59718b9b5d03@192.168.1.73:5060
CSeq: 2 REGISTER
Server: Asterisk PBX 16.30.0-vici
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="67.220.85.61", nonce="18756574"
Content-Length: 0

now I tried to register using Zoiper from same computer same network and got:

2024/06/14 08:34:49.344642 87.116.135.135:12870 -> 67.220.85.61:5060
REGISTER sip:67.220.85.61;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 87.116.135.135:12870;branch=z9hG4bK-524287-1---67dceca7875277f3;rport
Max-Forwards: 70
Contact: sip:2002@87.116.135.135:12870;transport=UDP;rinstance=116ef37cd6b2b401
To: sip:2002@67.220.85.61;transport=UDP
From: sip:2002@67.220.85.61;transport=UDP;tag=6571331d
Call-ID: SQV64kjeukXBW-KTfrV85Q..
CSeq: 1 REGISTER
Expires: 60
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Supported: replaces, norefersub, extended-refer, timer, sec-agree, outbound, path, X-cisco-serviceuri
User-Agent: Z 5.6.4 v2.10.20.4_1
Allow-Events: presence, kpml, talk, as-feature-event
Content-Length: 0

2024/06/14 08:34:49.344928 67.220.85.61:5060 -> 87.116.135.135:12870
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 87.116.135.135:12870;branch=z9hG4bK-524287-1---67dceca7875277f3;received=87.116.135.135;rport=12870
From: sip:2002@67.220.85.61;transport=UDP;tag=6571331d
To: sip:2002@67.220.85.61;transport=UDP;tag=as113c8db1
Call-ID: SQV64kjeukXBW-KTfrV85Q..
CSeq: 1 REGISTER
Server: Asterisk PBX 16.30.0-vici
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="67.220.85.61", nonce="3493b9b1"
Content-Length: 0

2024/06/14 08:34:49.576569 87.116.135.135:12870 -> 67.220.85.61:5060
REGISTER sip:67.220.85.61;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 87.116.135.135:12870;branch=z9hG4bK-524287-1---73c1403a9406ee57;rport
Max-Forwards: 70
Contact: sip:2002@87.116.135.135:12870;transport=UDP;rinstance=116ef37cd6b2b401
To: sip:2002@67.220.85.61;transport=UDP
From: sip:2002@67.220.85.61;transport=UDP;tag=6571331d
Call-ID: SQV64kjeukXBW-KTfrV85Q..
CSeq: 2 REGISTER
Expires: 60
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Supported: replaces, norefersub, extended-refer, timer, sec-agree, outbound, path, X-cisco-serviceuri
User-Agent: Z 5.6.4 v2.10.20.4_1
Authorization: Digest username="2002",realm="67.220.85.61",nonce="3493b9b1",uri="sip:67.220.85.61;transport=UDP",response="16f77e3e7ddb724fccd20ef91085f83c",algorithm=MD5
Allow-Events: presence, kpml, talk, as-feature-event
Content-Length: 0

@ivanvujisic
Copy link
Author

Anybody?

@Rob-28
Copy link

Rob-28 commented Jun 24, 2024

Hi,

I am using this package in combination with PJSIP in Asterisk. I configured the endpoint with the same authentication and endpoint name, as differing values appeared to cause authentication failures.

I also applied this patch in order to get Asterisk's polling to work when "qualify" is enabled.
#177 (comment)

You could also look at the fork made by the author of the patch.

@ivanvujisic
Copy link
Author

Actually I'm using Vicibox11 with chan_sip, is that what makes issue?

@Rob-28
Copy link

Rob-28 commented Jun 27, 2024

Do you have any issues when using Zoiper with the phone 2005@..., user 2005 and password ***?
The log you have sent suggests that that also does not work as:

2024/06/14 08:34:49.344928 67.220.85.61:5060 -> 87.116.135.135:12870
SIP/2.0 401 Unauthorized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants