but when i try to run this (by dialing 999 from my phone), i get the logs in asterisk CLI:
-- Executing [999@default:1] Answer("SIP/1*8710-00000007", "") in new stack
> 0x7fea3804cd40 -- Strict RTP switching to RTP target address 10.10.6.6:12470 as source
-- Executing [999@default:2] AGI("SIP/1*8710-00000007", "/var/lib/asterisk/agi-bin/test_agi.py") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/test_agi.py
-- <SIP/1*8710-00000007>AGI Script /var/lib/asterisk/agi-bin/test_agi.py completed, returning 0
-- Executing [999@default:3] Hangup("SIP/1*8710-00000007", "") in new stack
== Spawn extension (default, 999, 3) exited non-zero on 'SIP/1*8710-00000007'
And the agi_try.log file is empty in /tmp folder.
my dialplan looks like:
exten => 999,1,Answer()
same => n,AGI(/var/lib/asterisk/agi-bin/test_agi.py)
same => n,Hangup()
Everything was working well but suddenly it stopped. I have even tried redirecting the logs as well (as seen in my script above) but still the AGI fails immediately now.
Can someone point me in the right direction of what the issue could be?
As mentioned by others, don’t do this. (The redirection to FD 2, stderr, is fine.)
Or this sort of thing. Write your debug messages to stderr, because stdout is used for AGI communication with Asterisk. E.g.
sys.stderr.write("Starting AGI script\n")
And don’t do this either. Just let Python write the exception report itself to stderr and terminate your script. It can do it more reliably than you can.
Hi @ldo
sorry for writing back late…
the issue happens particularly when I restart the Asterisk service via systemctl…can you guide me why is this happening?
Yes @ldo , I have noticed when the channel does not hang up and i try to restart the service using systemctl, that’s when the agi stops working. I restarted Asterisk by killing its PID and it worked. Then again, I ran my python script, and it got stuck in the middle, and the channel went into auto-destruct mode, so I had to restart the service (graceful restart did not work). When I did that, my AGI stopped responding again, and I got the following output when running the command:
/usr/bin/python3 -c 'import asterisk.agi; print("AGI module OK")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'asterisk'