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.