Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to start learning Python - and I'm having trouble getting scripts to load up in a browser (using Wamp). So far I've tried the following:

1: add the following lines to httpd.conf:

AddHandler cgi-script .py
Options ExecCGI

I navigate to

  • but get an Internal Server error.

2: downloaded - renamed to mod_wsgi (running Wamp with Apache 2.2) added the following lines to httpd.conf

AddHandler mod_wsgi .py
WSGIScriptAlias /wsgi/ "path/to/my/pythonscripts/folder/"

but when I navigate to the script at

  • it renders the script in it's entirety i.e.

    !c:/Python26/python.exe -u

    print "hello world"

I managed to get CherryPy working, but ideally I want to learn the language in a relatively raw context before digging into a framework. Can anyone give me some pointers?

share|improve this question
up vote 3 down vote accepted

You're mixing your goals. if you

want to learn the language in a relatively raw context before digging into a framework

then forget about the browser for a while.

Open a text editor, a command window and the interpreter (or a nice shell on the interpreter, like ipython). When you get the hang of the language, and what does it do, and how, then (and only then) start using it to create web pages.

When you get to the web environment, using a framework is optional. You can simply build HTML to stdout, and be called like CGI, or fire up a wsgi server and write wsgi handler functions, or Cherry py, to simply attach functions to URLs, or go full stack with Django, where you define classes and other setups to describe your infrastructure (database model, html forms, template tags, etc), and then (again) attach functions to URLs

share|improve this answer
thanks for your help. I actually got through Beginning Python to the point where you started executing scripts on a browser, but life got in the way so I've just returned to the book, and a fresh installation on my machine means I lost the wsgi setup I had working the last time...guess I should go back to the beginning! thanks SWK – sunwukung Apr 29 '10 at 15:05
note that in any case, python scripts are not executed on the browser. they're executed on the web server and as a result, send HTML to the browser for display. a broswer only executes JS and whatever a plugin implements (java, flash, CLR) unless you find a python plugin for browsers, keep python on the server (at least until pyjamas' python->JS compiler gets beyond the 'just a toy' phase) – Javier Apr 29 '10 at 15:29

You can't feed CGI scripts into mod_wsgi for a start.

Also, because you didn't bother providing the exact configuration you used, including the URL, one can only guess what you have done wrong.

For mod_wsgi make sure you read:

share|improve this answer
no, I know you can't feed cgi scripts to mod_wsgi, which is why I tried CGI first. Failing that, I tried mod_wsgi - following the guide on the site (i.e the url you posted). That didn't work, so I came here for some guidance... – sunwukung Apr 29 '10 at 3:24
Your post shows CGI script being returned, so the URL you used wasn't even being directed at a WSGI script, but the CGI script. As I say, provide exact information as to paths and URLs used. Don't use .py extension for WSGI, use a .wsgi extension as the documentation says so that you don't run risk of the .py file being interpreted as CGI due to an existing configuration for CGI and Python. Finally, you can't have followed the documented instructions anyway, as they do not say to use AddHandler and WSGIScriptAlias at the same time. Start with first example in documentation and get it working. – Graham Dumpleton Apr 29 '10 at 4:00
thanks, that clears things up a bit. Can I simply save a regular .py script with a .wsgi extension? – sunwukung Apr 29 '10 at 15:03
Yes and no. It has to be a valid WSGI application providing a 'application' callable object which is the application entry point. There are some limitations as to what code can do in that specific WSGI script file as described in '';, but that only applies to that file and not other Python modules which make up your application. – Graham Dumpleton Apr 29 '10 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.