Python configuration question when python scripts are executed using Appweb as web server.

IronyOfLife mydevforums at gmail.com
Mon Aug 3 16:04:07 CEST 2009


Hi All

I have installed python 2.6.2 in windows xp professional machine. I
have set the following environment variables -- PYTHONPATH. It points
to following windows folders: python root folder, the lib folder and
lib-tk folder. I have configured IIS to execute python scripts.

I do not have any issues executing python scripts from the python
interpreter window or from the browser using IIS as the web server.

However, when I use the open source Appweb web browser to execute
python scripts. It is able to execute only simple script without
issues. For example, hello.py executes fine.

hello.py
--------------------------------------------------------
#!/usr/bin/env python

print "Content-type: text/html\n\n"
print "<html>Hello world!</html>"

However I am not able to execute python scripts that contain import
statements. I need to point out here that i do not have issue with
using os or sys packages. When I tried to execute the sample client
script that came with the gnutls wrapper for python, I got error. I
narrowed it down to the "from ... import" line in the example.

from gnutls.crypto import *
from gnutls.connection import *

Next I modified it to the functions used in the client python scripts
(NOTE: I have added some additional functions to connection and crypto
python scripts).
from gnutls.crypto import X509Certificate, X509PrivateKey, X509CRL
from gnutls.connection import AnonClientCred

Next step, in order to debug, I used the module finder to see what is
happening. To being with I used the module finder to find out the
modules loaded for the simple script hello.py.

hello2.py
--------------------------------------------------------
#!/usr/bin/env python

import modulefinder

import pdb

pdb.set_trace()

finder = modulefinder.ModuleFinder()
finder.run_script('hello.py')

print "Content-type: text/html\n\n"
print "<html>"

print sys.exc_info()

print 'Loaded modules:'
for name, mod in finder.modules.iteritems():
    print '%s: ' % name,
    print ','.join(mod.globalnames.keys()[:3])

print '-'*50
print 'Modules not imported:'
print '\n'.join(finder.badmodules.iterkeys())

print "</html>"

I got the error. Please see below for error as captured from Appweb
logs. See lines 3 to 5.

       cgi:5 main  356: CGI Response: read 89 bytes
       cgi:6 main  356: Data is:
> c:\appweb\web\hello2.py(9)<module>()
-> finder = modulefinder.ModuleFinder()

(Pdb)

       cgi:5 main  356: CGI Response: read 0 bytes
       cmd:7 main  getExitCode: process 0, code 1
   default:1 main  Error: 503 "Service Unavailable" for "/hello2.py",
file "c:/appweb/web/hello2.py": CGI process /hello2.py: exited
abnormally with exit code: 1
   request:5 main  356: flushOutput: background 0

Once again, let me stress that this issue is happening only when I use
appweb as the web server.

Some details on Appweb that I found out: Appweb opens up a new console
process and executes the python scripts. See sample below:

cmd:5 pool.0  Running: C:\Dev\Ironic\Tools\Python26\python.exe c:/
appweb/web/hello2.py

When python scripts are executed in this fashion, should there be
additional command line arguments be passed? Am I missing any
additional settings. Also can you help with improving the debugging
lines in hello2.py so that I can identify the issue.

Please help.

Thanks.

Ram G.



More information about the Python-list mailing list