I am running a python script through AGI, and I set differents cases in the scripts, but always return Success although I raise an exception in the script.
The part of the plan that call AGI is:
same => n,AGI(rest_call.py,${CALLER_ID})
same => n,Set(RESULT=${AGISTATUS})
same => n,NoOp(Return Code: ${RESULT})
same => n,GotoIf($[“${RESULT}” = “SUCCESS”]?success:fail)
same => n(success),NoOp(El caso fue exitoso)
same => n,Playback(es_419/custom/ok_rest)
same => n,Hangup()
same => n(fail),NoOp(El caso NO fue exitoso)
same => n,Playback(es_419/custom/error_rest)
same => n,Hangup()
What does raising an exception actually do in your script? AGI itself has no idea about exceptions, it just launches a script and does some back/forth. In this case it sounds like the AGI was successfully launched.
What does raising an exception actually do in your script? AGI itself has no idea about exceptions, it just launches a script and does some back/forth. In this case it sounds like the AGI was successfully launched.
Looks to me that the OP isn’t really using AGI. They are using the AGI applications to launch a non-AGI compliant script. I can’t find anything that instantiates an AGI class library, or otherwise does the AGI initialisation, and they are passing parameters on the command line.
They need to use AGI properly, for which they should read the basic documentation, rather than asking for canned code, or should use System, instead of AGI.
Thank You for your answers.
I reslved the problem using the following command in python script
print(f’SET VARIABLE “RESULT” “FAILED”')
Where RESULT is a Channel Variable.
But I couldn’t do the same throught AGI library
I don the following in the code
And when I run from Asterisk Server throught the following error
File "/usr/local/lib/python3.11/dist-packages/pyst2-0.5.1-py3.11.egg/asterisk/agi.py", line 628, in verbose
self.execute('VERBOSE', self._quote(message), level)
File "/usr/local/lib/python3.11/dist-packages/pyst2-0.5.1-py3.11.egg/asterisk/agi.py", line 150, in execute
return self.get_result()
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/pyst2-0.5.1-py3.11.egg/asterisk/agi.py", line 180, in get_result
code = int(code)
^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
I couldn’t install the library pyst2 with pip, because Asterisk is installed in Debian 12 and I had to to clone the repository and run the setup.py.
Any idea if it’s missing some library in the server.