Fedora Linux Support Community & Resources Center
Old 17th April 2012, 12:55 PM
sea Offline
"Shells" (of a sub world)
Join Date: May 2011
Location: Confoederatio Helvetica (Swissh)
Age: 37
Posts: 4,277
Python displayed on http?


Lets say i have a simple python script:

import sys

print("Content-Type: text/plain\n\n")
print("I'm serving python version ", sys.version, " located in ", sys.path)
Which resides inside my www/python directory.

What i had tried is to call it through php, with a include call, figured that either no php was installed, or the include didnt work at all.
I tend to say php is not installed, as an "echo" command inside the php section remained silent.

I had searched google for "how to display python on http", what i had found are plenty of python scripts, but none of them seemed to be 'callable' through webaccess.
That means, how do i display the script properly on the browser?
If i call it with http://URL/python/script.py all i get is the plain text.

Thanks in advance

Basicly my question is: How do i call the python script from html?
With the search term above, i only get results on how to generate html from phyton, which is not what i want.
So, suggestions for another search term are very welcome.

Thought i post the things i had found, but dont help me any further (maybe i dont understand them properly )
If i copy paste them onto the server, the html parts are displayed, but the python code is displayed either.. the code, not the 'result' of the code
EFI Cheatsheet :: http://forums.fedoraforum.org/showthread.php?t=298546
Video Handler Script (VHS) (mass re-encode videos, screenrecorder, console music/webradio player, ...) :: http://forums.fedoraforum.org/showthread.php?t=299182
Windows 8+ & Fedora 20+ Dualboot :: http://forums.fedoraforum.org/showthread.php?t=298161

Last edited by sea; 17th April 2012 at 03:49 PM.
Reply With Quote
Old 17th April 2012, 03:59 PM
Posts: n/a
Re: Python displayed on http?

Python is like Perl, you use it to build your application. Never heard of ability to embed Python to a PHP script either.
Good info on web programming with Python: http://wiki.python.org/moin/WebProgramming

You also need mod_python installed on Apache.
Reply With Quote
Old 19th April 2012, 07:23 PM
rolandm Offline
Registered User
Join Date: Apr 2012
Location: Finland
Posts: 6
Re: Python displayed on http?

What you wrote is basically a CGI program: to make Apache executing the script, it has to be declared as script e.g. using the directive ScriptAlias.

More information at httpd.apache.org in /docs/2.0/howto/cgi.html

A plain CGI script must do everthing itself. As far as I still remember (it's a long time ago I've used CGI ):
  • print the content type
  • print an empty line
  • print the html document

As alternative you could use mod_python Apache module. Using mod_python you basically use an embedded Python interpreter inside Apache rather than then CGI (=common gateway interface?) that is not aware of whether Python or any other script or binary is used.

See more information at /www.modpython.org in Tutorial: /live/current/doc-html/tut-what-it-do.html.

I expect that mod_python is more performant and in the long run easier to use than using Python scripts as plain CGI scripts. I never used it but this guess is based on using mod_perl that provides similar functionality for Perl in Apache.

PS: obviously I am considered as too dangerous to post URLs as urls
Reply With Quote
Old 28th April 2012, 11:45 PM
marko Offline
Registered User
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 7,121
Re: Python displayed on http?

Note, your script quote post #1 first line is wrong:


should be


at least on a standard Fedora system, python is in the /usr/bin directory
Reply With Quote

displayed, http, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP:// treated differently than http:// dengeltrees Using Fedora 5 16th April 2011 03:00 AM
Error With Python / Python-Twisted-Web HMSS013 Using Fedora 6 11th November 2010 05:07 AM
Python, IDLE, Python-tools Gnome. Deonis Using Fedora 2 12th March 2009 03:44 AM
HTTP Install through HTTP Proxy Jygar Using Fedora 1 7th November 2005 04:36 PM
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Using Fedora 0 15th September 2005 05:53 PM

Current GMT-time: 03:23 (Sunday, 24-09-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat