I’m new with Python and I’m trying to write a sample program using pyVoIP that waits for an incoming call, reads the calling number, terminates the call and calls it back.
This is the code:
from pyVoIP.VoIP import VoIPPhone, CallState, InvalidStateError
anum = ''
def answer(call): # This will be your callback function for when you receive a phone call
try:
print(call.state)
anum = call.request.headers["From"]["number"]
call.answer()
call.hangup()
except InvalidStateError:
pass
if __name__ == "__main__":
vp = VoIPPhone('79.98.45.133',5060,'0662279775','065+eMl6Ttd6$T',callCallback=answer)
vp.start()
# call = vp.call('+393292100441')
print(vp._status)
print(CallState)
input("Press enter to disable the phone")
call = vp.call(anum)
vp.stop()
The registration is ok, I succeded in getting the calling number but I get the following error:
Exception in thread SIP Recieve:
Traceback (most recent call last):
File "/home/gtorassa/pyVoIP/projects/qosroaming/.venv/lib/python3.11/site-packages/pyVoIP/util.py", line 17, in acquired_lock_and_unblocked_socket
socket.setblocking(False)
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib/python3.11/threading.py", line 1394, in run
self.function(*self.args, **self.kwargs)
File "/home/gtorassa/pyVoIP/projects/qosroaming/.venv/lib/python3.11/site-packages/pyVoIP/SIP.py", line 853, in recv_loop
with acquired_lock_and_unblocked_socket(self.recvLock, self.s):
File "/usr/lib/python3.11/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/home/gtorassa/pyVoIP/projects/qosroaming/.venv/lib/python3.11/site-packages/pyVoIP/util.py", line 20, in acquired_lock_and_unblocked_socket
socket.setblocking(True)
OSError: [Errno 9] Bad file descriptor
I’m using the virtual environment launched by:
python3 -m venv .venv
source .venv/bin/activate
I’m using Debian GNU/Linux 12 with kernel Linux 6.1.0-18-amd64
2