[Tutor] CGI Script Fails on import cgi

Kristin Wilcox wilcoxwork at gmail.com
Mon Nov 9 09:47:44 CET 2009


Hello,

As I've mentioned on the list before, I'm very new to Python and
programming in general. Now I'm trying my hand at writing very very
simple CGI scripts.  I basically wanted to try play with cgi scripting
as I feel my way around Python. I'm uploading to my account on my
university's server.

Unfortunately, I error out whenever I do 'import cgi'. I'm hoping to
receive some advice! Thanks in advance for reading all this.

Facts:
1. From what I can tell, the server is Red Hat Enterprise Linux with
Apache 1.3.33.

2. I have successfully executed .cgi scripts that only included
printing text or html.

3. I've tried adding form validation with cgi.FieldStorage() and it
would run in the server command line okay as .py, without syntax
errors.

4. However, these same scripts including cgi.FieldStorage() would fail
to execute when uploaded as a cgi script. I get this error:
"CGI Script Failure
The web page you attempted to access seems to have a problem: the
script failed before sending any headers. "

4. I tested by adding only 'import cgi' to one of my html printing
files that worked, to confirm that it was the sole problem. That
script failed - so I knew the module import was it.

5. I then used try: import cgi, except: traceback.format_exc(None)
I received this:
Traceback (most recent call last): File "cgi_errors.cgi",
line 9, in  import cgi File
"/usr/local/depot/python.1250025008/lib/python2.6/cgi.py",
line 40, in  import urllib File
"/usr/local/depot/python.1250025008/lib/python2.6/urllib.py",
line 26, in  import socket File
"/usr/local/depot/python.1250025008/lib/python2.6/socket.py",
line 46, in import _socket
ImportError: ld.so.1: python: fatal: relocation error: file
/usr/local/depot/python.1250025008/lib/python2.6/lib-dynload/_socket.so:
symbol inet_aton: referenced symbol not found


6. From the command line I typed python2.6, and then asked for
sys.path, sys.modules["cgi"], sys.modules["socket"], and
sys.modules["urllib"], and sys.modules["_socket"] and this is what it
gave me:

'/usr/local/depot/python.1250025008/lib/python26.zip',
'/usr/local/depot/python.1250025008/lib/python2.6',
'/usr/local/depot/python.1250025008/lib/python2.6/plat-linux2',
'/usr/local/depot/python.1250025008/lib/python2.6/lib-tk',
'/usr/local/depot/python.1250025008/lib/python2.6/lib-old',
'/usr/local/depot/python.1250025008/lib/python2.6/lib-dynload',
'/usr/local/depot/python.1250025008/lib/python2.6/site-packages',
'/afs/umbc.edu/common/python26/i386_linux26/lib/python2.6/site-packages'
<module 'cgi' from '/usr/local/depot/python.1250025008/lib/python2.6/cgi.pyc'>
<module 'urllib' from
'/usr/local/depot/python.1250025008/lib/python2.6/urllib.pyc'>
<module 'socket' from
'/usr/local/depot/python.1250025008/lib/python2.6/socket.pyc'>
<module '_socket' from
'/usr/local/depot/python.1250025008/lib/python2.6/lib-dynload/_socket.so'>

Any advice would be much appreciated!

- Kris


More information about the Tutor mailing list