Jump to content

Recommended Posts

Posted

Hello, I am using Heliohost's free hosting, I want to know how exactly to deploy python over here..I have never done that in the past. For instance, suppose I have a simple a.py file with a simple print "Hello world" - where do I exactly put it? I tried putting it in cgi-bin and trying <my-domain>/cgi-bin/a.py but got an Internal Server Error.

 

Any help would be appreciated.

Posted

Here is a Hello World Python Script to get you started.

#!/usr/bin/python
print "Content-Type: text/html\n\n";
print "Hello";

You can make that python file with extension ".py" in cgi-bin folder or have this in the ".htaccess" file of the folder in which you want Python scripts to be executed.

AddHandler cgi-script .cgi .pl .py
Options +ExecCGI

  • Like 1
Posted

Fine but if I try to execute a simple php script that passes variables to a python script using passthru(), it says the function is disabled for security reasons.

In that case is it impossible to pass variables to my python script from my php script? Any alternatives?

Posted

You could pass the data as GET or POST data if your Python script receives web requests (PHP can do a file_get_contents or cURL request with GET/POST arguments, the function will return Python's output in PHP so you can get the results).

 

Passing them on the server side with things like passthru or exec won't work though. We don't allow those functions here. There's not many reasons to use both though. Perhaps write the program all in one language?

Posted
You could pass the data as GET or POST data if your Python script receives web requests (PHP can do a file_get_contents or cURL request with GET/POST arguments, the function will return Python's output in PHP so you can get the results). Passing them on the server side with things like passthru or exec won't work though. We don't allow those functions here. There's not many reasons to use both though. Perhaps write the program all in one language?

 

&--#60;?php
$a="hello world";
$o = passthru("python a.py ".$a);
echo $o;
?&--#62;

 

This is my simple php code which I am using to test. My python code is

#!/usr/bin/python
import sys
print "Content-Type: text/html\n\n";
s= "Hello world from python"
print s
#print sys.argv[1]
return s

 

Can you please tweak this so that it becomes a bit clearer what exactly you're saying..?

Sorry am a beginner so a bit clueless on this..

 

As far as I know, GET/POST is used to get the values in php, but I want my python script to work with the variables from the php script. That's where I'm stuck. How do I have my Python file to read those variables?

 

EDIT : Got it to work...thanks

Guest
This topic is now closed to further replies.
×
×
  • Create New...