System() won't run python script on pi3

I want to run this python script from the dialplan. when i run it in the console over ssh, there is no problem. but in asterisk happens nothing.


#!/usr/bin/env python
import paho.mqtt.client as mqtt
broker_address=“” #broker_address=“broker”
port=1883 #port
client = mqtt.Client(“P1”) #create new instance
client.connect(broker_address) #connect to broker
client.disconnect() #connect to broker


exten => 100,1,Answer()
same => n,system(python /var/lib/asterisk/agi-bin/mqtt-go)
same => n,Hangup()

Anyone got an idear ?

Most of the time this issue is related to permission issue or path no found when running this script on the Asterisk dialplan

Permissons are set to 755. How can i debug the dialplan when executed ? i get no feedback when calling.

Using env, with nothing but a command, seems pointless and won’t fix a missing PATH variable. You should always give the full path to Python.

System() do not provide any output, AGI() does when debug is enabled

i tried asterisk -rvvv in console. but didn’t help me much.
Executing [100@from-internal:2] System(“PJSIP/80-00000085”, “python /var/lib/asterisk/agi-bin/mqtt-go”) in new stack

followed by the next step in diaplan. but no more info


#!/usr/bin/env python

same => n,system(python /var/lib/asterisk/agi-bin/mqtt-go)
same => n,system(/usr/bin/python2.7 /var/lib/asterisk/agi-bin/mqtt-go)

changed nothing. console works fine, diaplan doesn’t.

Try AGI() function, and keep AGI debug enabled on console.

Have added system and agi to the dialplan. both with no result so far.

– Executing [100@from-internal:2] System(“PJSIP/80-0000008c”, “/usr/bin/python2.7 /var/lib/asterisk/agi-bin/mqtt-go”) in new stack
– Executing [100@from-internal:3] AGI(“PJSIP/80-0000008c”, “mqtt-go”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/mqtt-go
<PJSIP/80-0000008c>AGI Tx >> agi_request: mqtt-go
<PJSIP/80-0000008c>AGI Tx >> agi_channel: PJSIP/80-0000008c
<PJSIP/80-0000008c>AGI Tx >> agi_language: en
<PJSIP/80-0000008c>AGI Tx >> agi_type: PJSIP
<PJSIP/80-0000008c>AGI Tx >> agi_uniqueid: 1546159094.142
<PJSIP/80-0000008c>AGI Tx >> agi_version: 13.24.0
<PJSIP/80-0000008c>AGI Tx >> agi_callerid: 80
<PJSIP/80-0000008c>AGI Tx >> agi_calleridname: Handy
<PJSIP/80-0000008c>AGI Tx >> agi_callingpres: 0
<PJSIP/80-0000008c>AGI Tx >> agi_callingani2: 0
<PJSIP/80-0000008c>AGI Tx >> agi_callington: 0
<PJSIP/80-0000008c>AGI Tx >> agi_callingtns: 0
<PJSIP/80-0000008c>AGI Tx >> agi_dnid: 100
<PJSIP/80-0000008c>AGI Tx >> agi_rdnis: unknown
<PJSIP/80-0000008c>AGI Tx >> agi_context: from-internal
<PJSIP/80-0000008c>AGI Tx >> agi_extension: 100
<PJSIP/80-0000008c>AGI Tx >> agi_priority: 3
<PJSIP/80-0000008c>AGI Tx >> agi_enhanced: 0.0
<PJSIP/80-0000008c>AGI Tx >> agi_accountcode:
<PJSIP/80-0000008c>AGI Tx >> agi_threadid: 1858667552
<PJSIP/80-0000008c>AGI Tx >>
– <PJSIP/80-0000008c>AGI Script mqtt-go completed, returning 0

Dont know if your issue could be while importing the module, could be that import statement can not find the module searched, when doing this operation from Asterisk

I don’t know what to do anymore. I’m thinking of trying to use a PHP script to achive the same thing.


But I think that library require some kind of environment variables that are not found when is called from Asterisk or permission to some system resouces that are not accesible from Asterisk assuming you re running Asterisk as non root user

Yeah, i build a work around from the other end.
I let the dialplan make record(file.wav,1,1,q) and listen from the node red part with a watch node, that triggers the rest. not my first choice but this one is working. put it in a sub which i call evertime i need the trigger.