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

Heyas

Lets say i have a simple python script:
Code:
#!/bin/python

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
sea

EDIT:
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.

EDIT:
Thought i post the things i had found, but dont help me any further (maybe i dont understand them properly )
http://docs.python.org/howto/webservers.html
http://wiki.python.org/moin/CgiScripts
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
__________________
Laptop: Toshiba satellite p50-a-11 CPU: Intel i7 8*2400 MHz GPU: GeForce GT 745M RAM: 8192 MB Distro: Fedora (Rawhide) DE: Awesome
Text User Interface (TUI) // Windows 8+ & Fedora 20+ Dualboot

Last edited by sea; 17th April 2012 at 03:49 PM.
Reply With Quote
  #2  
Old 17th April 2012, 03:59 PM
pete_1967 Online
Clueless in a Cuckooland
 
Join Date: Mar 2006
Location: Here now, elsewhere tomorrow.
Posts: 4,273
linuxfirefox
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.
__________________
A Drink is Not Just For Christmas - SaskyCom :thumb:


“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime” so now go and...
RTFM FIRST: http://docs.fedoraproject.org/ & http://rute.2038bug.com/index.html.gz
Reply With Quote
  #3  
Old 19th April 2012, 07:23 PM
rolandm Offline
Registered User
 
Join Date: Apr 2012
Location: Finland
Posts: 6
linuxfedorakonqueror
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
  #4  
Old 28th April 2012, 11:45 PM
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 6,000
linuxfirefox
Re: Python displayed on http?

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

#!/bin/python

should be

#!/usr/bin/python

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

Tags
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 04: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 03: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: 16:49 (Tuesday, 29-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

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