I want to execute a python script from php script which will send a curl request to a web api and will return the output of the curl request to php script which will print it or do further processing.The problem is when I run the python script independently it produces correct output but when it is called from php script it doesn't work
I have tried changing permissions for the htdocs folder on xampp server and since I thought the image file which is being uploaded to server via api request is not accessible.
This is the part of php script which executes the python script
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
sleep(5);
$command = escapeshellcmd('python3 /opt/lampp/htdocs/script.py');
$output = shell_exec($command);
echo $output;
}
This is the python script
#!/usr/bin/env python
import sys
import subprocess
import os
import ast
import requests
from time import sleep
import datetime
file = open('/opt/lampp/htdocs/count.txt','r')
uid=file.read().strip()
file.close()
print(uid)
pipe = subprocess.Popen('curl -X POST "https://api-
us.faceplusplus.com/facepp/v3/detect" -F
"api_key=some_key" \
-F "api_secret=some_key" \
-F "image_file=@/opt/lamppp/htdocs/image.jpg"', stdout=subprocess.PIPE, shell=True,
universal_newlines=True)
j = pipe.stdout.readlines()
print(j)
Expected output should print something like this when php page is called.
['{"image_id": "mprd5Pjd9ni+sPD4fWzv9g==", "request_id": "1554044606,8bba1d32-9b73-4457-a024-cb3ad66ee349", "time_used": 623, "faces": [{"face_rectangle": {"width": 134, "top": 159, "left": 242, "height": 134}, "face_token": "a0bc6e53782d0c38a837187a832da542"}]}'
but it prints empty sqaure braces.[]