Solved

Python on WAMP: Error When Trying to Run .py Script

Posted on 2007-04-06
6
1,426 Views
Last Modified: 2012-05-05
I'm trying to test a Python script on WAMP.  I have a working WAMP installation, and followed instructions to add Python (on this page: http://www.mplstutorial.com/wamp_python/python_wamp.html ), except that everything is on the D: drive.  I also restarted the WAMP Server.  
      This error appears when I try to run a page with the .py extension:

  Mod_python error: "PythonHandler default"

  Traceback (most recent call last):

  File "D:\Python24\Lib\site-packages\mod_python\apache.py", line 287, in HandlerDispatch
    log=debug)

  File "D:\Python24\Lib\site-packages\mod_python\apache.py", line 461, in import_module
    f, p, d = imp.find_module(parts[i], path)

   ImportError: No module named default
0
Comment
Question by:Randall-B
  • 4
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
RichieHindle earned 250 total points
ID: 18865166
Saying "PythonHandler default" means "I want all requests to be handled by default.py".  If you have no default.py, you'll get that ImportError.

If you've taken the exact httpd.conf from that "Running Python with WAMP5" page, it's configured for requests for "index.py" and "xa.py" to be handled by those files, and for all other requests to be handled by default.py.  (See the section <Directory "C:/wamp/www/"> in httpd.conf)

If you want a URL like "http://myserver/mymodule.py" to run mymodule.py, you need to use mod_python's CGI Handler: "PythonHandler mod_python.cgihandler"

See http://www.modpython.org/live/current/doc-html/hand-cgi.html for the CGI Handler documentation.

0
 

Author Comment

by:Randall-B
ID: 18865440
RichieHindle,
   Thanks. I'm just trying to run a script like HelloWorld.py in my www directory.  

Then I put the .htaccess file in the   www  directory, with:
     SetHandler mod_python
     PythonHandler mod_python.cgihandler
as recommended on the modpython page, then restarted the server.
    The error messages went away.  But now only a blank screen appears; it does not print anything to the browser.  (However, the HelloWorld.py script *does* run from the command line.)

I tried the bang line as:
     #!/usr/bin/python
and also as:
    #!D:\Python24
but either way, the script will not run properly when called from the url like
     http://localhost/HelloWorld.py

 What could be wrong?
0
 
LVL 14

Assisted Solution

by:RichieHindle
RichieHindle earned 250 total points
ID: 18865530
The shebang line should probably be:

#!D:\Python24\python.exe

but that shouldn't matter for mod_python.

Try this HelloWorld.py:

#!D:\Python24\python.exe
print "Content-Type: text/plain\n\n"
print "Hello, World!\n"
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:Randall-B
ID: 18865587
Yes, that worked, even without the   .exe  
  Looks like the problem was, I forgot the header
         print "Content-Type: text/plain\n\n"

So, overall, the problems were the   .htaccess  statements and the content-type header.

It seems to be working now. Thanks!
0
 

Author Comment

by:Randall-B
ID: 18866205
RichieHindle,
   If you happen to see this, even though it's PAQ'd, I discovered an unintended problem with the .htaccess file:  when it is in my   www  directory, Python files will run, but html files treated as if not even there.  So I had to delete or comment-out the .htaccess statements just to be able to view  html  files on localhost again.
    Maybe the statements in .htaccess can be modified to allow both kinds of files to work simultaneously?  Thanks.
0
 

Author Comment

by:Randall-B
ID: 18866256
You are invited to comment on my related question at:
http:/Q_22496947.html  .  Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question