I am trying to run A python Script as mentioned in the following link..

Running a python script within wordpress

But I am still getting the message "permission denied".

  • Does your script have the 'x' executable permission set for the user your web server is running as? (However it might be better to call the python interpreter explicitly, rather than just running the .py script directly, else you've really written a 'run arbitrary command' shortcode not a python shortcode.) – Rup Nov 25 '20 at 9:16
  • yes. it is having permission.. – shekhar singhal Nov 30 '20 at 8:22
  • OK, then you're going to have to work out where the 'permission denied' is coming from then. I don't think you've given us enough information to help you. – Rup Nov 30 '20 at 8:24

This issue of permission denied is resolved.. Permission was already given but I have added 'env python' in the popen function.. Now the code is running as expected..

add_shortcode( 'run_test_py', 'test_py' );

function test_py( $attributes )
    $data = shortcode_atts(
            'file' => 'test.py'

    $handle =  popen('env python '. __DIR__ . '/' . $data['file'] . ' 2>&1', 'r' );
    $read = '';

    while ( ! feof( $handle ) )
        $read .= fread( $handle, 2096 );

    pclose( $handle );

    return $read;
  • env python doesn't require the script it's running to have execute permissions, so if that works and the old way doesn't you probably did have the permissions set incorrectly, or set for the wrong user or group. – Rup Nov 30 '20 at 23:57
  • previously I have given permission using cmd but that didn't work, then I tried with file explorer via Godaddy & gave the permission from there but still that didn't work. then I added "env python " then it worked. – shekhar singhal Dec 1 '20 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.