Hosting a python file

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
mukunda
A regular
A regular
Posts: 42
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Fri Nov 16, 2012 2:42 pm

Hosting a python file

Post by mukunda »

Can someone point me in the right direction to serving a python-based web service?

e.g., I created test.py in the public folder and tried to access it via http://domain/test.py, but get an HTTP 500. PHP files like test.php work fine. I saw there is supposed to be python/CGI support on the webserver information.

The content of the python file is just:
print("hello")

I also tried with a shebang "#!/usr/bin/python" and "chmox a+x test.py"
ImageImageImageImage
User avatar
Edge100x
Founder
Founder
Posts: 13027
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Hosting a python file

Post by Edge100x »

If you use the CGI method, you'll need to print the CGI header. For instance,

Code: Select all

#!/usr/bin/python

print("Content-type: text/html\n\n");
print("Hello, world!")
Using the WSGI method, things are a bit more complicated and might require extra configuration on our end, after you've installed the software.
mukunda
A regular
A regular
Posts: 42
Joined: Fri Nov 16, 2012 2:42 pm

Re: Hosting a python file

Post by mukunda »

Thanks, I should have known that - I know the php interpreter sends headers under the hood too
ImageImageImageImage
Post Reply