I am working on a Wordpress plugin embedding a Python script. I have uploaded the Python script to my server, and at first I got an error message on the web page, where my script is to be run, saying "permission denied" (I have redirected stderr to stdout to enable me to see the error messages). When I added execution permissions I instead get a "not found" message (done via Filezilla).
I can see the script is on the server in the correct folder, and it was apparently found earlier when the permissions were wrong. How can I get my plugin to find the Python file?
Here is the relevant PHP function in the plugin:
function embed_python( $attributes )
{
$data = shortcode_atts(
[
'file' => 'hello.py'
],
$attributes
);
$handle = popen( __DIR__ . '/' . $data['file'] . ' 2>&1', 'r' );
$read = '';
while ( ! feof( $handle ) )
{
$read .= fread( $handle, 2096 );
}
pclose( $handle );
return $read;
}
Turns out it was as simple as the server I was using (Loopia) needed the Python script in a certain folder to be able to find/run it, as well as several settings changed, see this Swedish page: https://support.loopia.se/wiki/python/.