Reputation: 11193
i'm using an API, which creates a JSON file when the python script is executed, so i've tried to use exec to run the python script and thne retrieve the json. However the python script does not seem to execute. What am i doing wrong? i'm trying it on a apache using MAMP
exec('python http://localhost:8888/examples/recent_matches_to_json.py');
$json = file_get_contents('http://localhost:8888/examples/recent_matches.json');
$obj = json_decode($json);
var_dump($obj->recent, true);
Upvotes: 0
Views: 54
Reputation: 5442
Uh... You should download the script and save it, then run the interpreter on it.
Something like:
$py_script = file_get_contents('http://localhost:8888/examples/recent_matches_to_json.py');
file_put_contents('recent_matches_to_json.py', $py_script);
exec('python recent_matches_to_json.py');
If you intend to download the script from the local computer, why not run it directly? Like exec('python /home/peter/site/examples/recent_matches_to_json.py')
.
You could also set up a web/WSGI server in that Python script so you could run it directly by just sending a HTTP request (like http://localhost:9999/recent_matches_to_json/
).
Upvotes: 1