简体   繁体   中英

Run python script through php on browser

I have a simple python script.

anubhaw.py

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
import pandas
cgitb.enable()

#print "Content-Type: text/plain;charset=utf-8"
print "Hello World! Trying !!"

I am trying to run it using this method mentioned on SO.

Contents of which are as follows:

<?php 
$command = escapeshellcmd('/home/iamaoxdo/public_html/cgi-bin/anubhaw.py');
$output = shell_exec($command);
echo $output;
//echo file_get_contents("/home/iamaoxdo/public_html/cgi-bin/test2.py");
?>

When am trying to run it on terminal(putty) am getting the output ie

iamaoxdo@iamanubhaw.com [~/public_html]# php -f python_php.php
Hello World! Trying !!
iamaoxdo@iamanubhaw.com [~/public_html]#

But when am trying to run in web browser (Chrome) it's just giving me a blank screen.

PS If I remove the import pandas , am getting the output as "Hello World! Trying !!" but once import pandas is added, it's showing me blank page.

I need pandas as my original script needs this module. I also bought VPS from namecheap for this purpose as python was not running properly on shared server.

Any ideas are welcomed. Thanks.

I encountered the seem issue with 'import pandas', or even with 'import openpyxl'. After try - except and print exception information, it turned out that one file of matplotlib was blocking reading by Webuser. Reinstall matplotlib with pip3 resolved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM