• Welcome to the new COTI server. We've moved the Citizens to a new server. Please let us know in the COTI Website issue forum if you find any problems.
  • We, the systems administration staff, apologize for this unexpected outage of the boards. We have resolved the root cause of the problem and there should be no further disruptions.

Testing a webserver for Python

Shonner

SOC-14 1K
Anyone happen to know how I can do a quick test to see if my webserver can host Python code and the version? I was able to upload some PHP code on it to run for seeing if PHP worked and what version it supports.

So I thought maybe there was maybe a .py file I could upload and try running to see. Otherwise, visitors would need to have Python installed when clicking on my .py files on my site, I'm guessing. Some people have a version of Python installed already, but they don't know it, and it isn't triggered on its own. It's usually a part of another app they use.
 
I don't think there#s any way to run Python code locally, directly from a web server. You'd run the Python code on the web server, perhaps as a cgi script.

How do you normally make a script or web page appear on your site? Just running a python script on the server won't make it reachable from a site. The way it usually works is you set up a mapping from your web server (e.g. Apache2) to invoke a script when someone selects a URL.

You can check if Python is installed by just running 'python' from a command line to run it interactively. It'll report it's version number on startup.

I'm no web dev though, I'm mainly a desktop guy, but if you get up and running I'd love to help out on the Python side of things.

Simon Hibbs
 
I don't think there#s any way to run Python code locally, directly from a web server. You'd run the Python code on the web server, perhaps as a cgi script.

Yep. That's what I'm seeing in examples on the net. I think I'll just keep with py2exe for now and let people just run the app on their computers locally.

How responsive are your webserver admins? Can you just email and ask them?

Takes a while. I could log in and do the whole "Manage Site" menu thing. Just takes a while to surf through it all to find what you're looking for, etc. It only took a minute for me to put PHP code on my site without going into my account to see what is available. So I had a brain fart and thought I could do the same with some Python code.
 
I am still trying to suggest ways to get your python code running on a web Server you have no control over. Please remember that I have close to no experience with Python, but while looking for a solution I discovered this:

http://docs.python.org/2/howto/webservers.html said:
Simple script for testing CGI

To test whether your web server works with CGI, you can use this short and simple CGI program:


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!"


Depending on your web server configuration, you may need to save this code with a .py or .cgi extension. Additionally, this file may also need to be in a cgi-bin folder, for security reasons.

You might wonder what the cgitb line is about. This line makes it possible to display a nice traceback instead of just crashing and displaying an “Internal Server Error” in the user’s browser. This is useful for debugging, but it might risk exposing some confidential data to the user. You should not use cgitb in production code for this reason. You should always catch exceptions, and display proper error pages – end-users don’t like to see nondescript “Internal Server Errors” in their browsers.

I hope this is helpful to you.
 
As Aramis says, you will need to install either a wrapper or an extension for your webserver as most don't support this kind of thing out of the box.

If you are running Apache as your web server, you can (or have) install mod_python.

Some web admin tools allow installing things like this.
 
Yep. That's what I'm seeing in examples on the net. I think I'll just keep with py2exe for now and let people just run the app on their computers locally.

BTW what libraries, such as UI framework are you planning on using? I love PyQT and PySide, they're both Qt toolkit wrappers. I used WxWidgets back in the day but hit too many limitations.

Simon Hibbs
 
BTW what libraries, such as UI framework are you planning on using? I love PyQT and PySide, they're both Qt toolkit wrappers. I used WxWidgets back in the day but hit too many limitations.

Simon Hibbs

I haven't tried too many yet. Haven't decided yet and/or don't know if I need a GUI for what my program does. If I do use a GUI, it will have the same look/feel as Windows as possible. No phone or tablet app style GUI. For now, the app would just work on Windows anyway.

ADDED:
Just looked. PySide is too new for my Python 2.5. And PyQT is using Python 2.7 and up. I'm not using Python 2.6 or later. When I'm more comfortable with everything I have for Python 2.5, and how it all fits together, I'll probably move to Python 3 (or 4, at the rate Python is updating now). But for now, all my books and libraries and GUIs and everything are working with my Python install.
 
Last edited:
You can get a slightly older PyQt version for py2.5 here:

http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.9.4/

I'll dig up some links and such. Qt apps look and work exactly like Windows apps, you really can't tell the difference, but if you are only interested in Widnows then the native libraries might make more sense.

I do all my personal development in Python 2.7 and use 2.6 at work. Not touched 3 yet.

Simon Hibbs
 
I thought I looked at PyQt-4.9.4 already, and there was one caveat about it. I'll take another look.

ADDED:
Ok. I ran the EXE installer everything seems to be running fine. I'm going through the demo folder now. The textedit.pyw sample saves in HTML and ODT. Not bad. Thanks for pointing me to this version.

The Export PDF doesn't do anything. But I can print to my free version of LULU's Soda PDF print driver. So I can get PDF output from these PyQt demos. Yey!

MORE ADDED:
Figured out that "--includes sip" is needed for py2exe to work with PyQt. That sip.pyd file was making me nervous just sitting there not being used.
 
Last edited:
Just bear in mind when Qt talks about rich text, it actually means HTML and not RTF, but there are various pure python libraries for document creation and conversion. Qt has a lot of very powerful features, but beyond the GUI framework stuff you're sometimes better off using a Python library that does the same sort of thing.

StarBase started off as a copy of the Diagram Scene example under the Graphics View examples folder, but I don't think there's any of the original code left at this point.

Simon Hibbs
 
I just found out about Brython. It uses Javascript to send Python code to web browsers that then run the code. Very cool. No Python install required by the user.
 
Back
Top