0

I am executing a python script from a php one by an exec command receiving an empty result. If I execute the python command from the shell, it correctly returns the right results, and the logs are silent; this is my php function:

public function poll($palina){
    //set_include_path("/var/www/html/iPhone/inarrivo/python");
    $pythonCommand="python3.4 ../../python/palina.py $palina";
    $result=exec($pythonCommand);
    echo "<blank>command=$pythonCommand result=$result</blank>";
    $resultData = json_decode($result, true);
    if (!is_array($resultData)) {
        error_log($resultData);
        $resultData=Array();
    }
    //print_r($resultData);
    return $resultData;
}

and this is the called python script:

#!/usr/local/bin/python3.4

# change above line to point to local 
# python executable

from xmlrpc.client import Server
from pprint import pprint
import sys, json
import datetime, time
palina=sys.argv[1]
DEV_KEY = 'UuC378Q3l3Y4vtF8q2Hj3i5Up6OmZKb2'

s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.Previsioni(token, palina, 'it')
#pprint(res)
arrivi=res.get('risposta').get('primi_per_palina')[0].get('arrivi')
myList=[]
for arrivo in arrivi:
    if 'nessun_autobus' not in arrivo and 'non_monitorata' not in arrivo:
        output={}
        acapolinea=arrivo.get('a_capolinea')
        output["busDestination"]=arrivo.get('destinazione')
        output["wait"]=arrivo.get('annuncio')
        if output["wait"]=='In Arrivo':
            output["receiving"]=1
        else:
            output["receiving"]=0
        meb=arrivo.get('meb')
        output["busNumber"]=arrivo.get('linea')
        output["busLines"]=arrivo.get('id_percorso')
        output["time"]=arrivo.get('tempo_attesa')
        output["stops"]=int(arrivo.get('distanza_fermate'))
        output["palina"]=arrivo.get('id_palina')
        output["inarrivo"]=arrivo.get('in_arrivo')
        partenza= arrivo.get('prossima_partenza')
        if acapolinea == 1:
            output["receiving"]=2
            output["acapolinea"]=acapolinea
            if partenza:
                s = datetime.datetime.strptime(partenza.value, "%Y%m%dT%H:%M:%S")
                output["capolineaDate"]=s.strftime('%H:%M')
        myList.append(output)
print (json.dumps(myList));

This script worked fine on a previous server. Is there some configuration to be set on Centos to have php and python correctly integrated?

1 Answer 1

2

The python script needs to have the full path in order to work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.