CGI Script Fails on import cgi

View: New views
3 Messages — Rating Filter:   Alert me  

CGI Script Fails on import cgi

by Kristin Wilcox :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: CGI Script Fails on import cgi

by Alan Gauld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


"Kristin Wilcox" <wilcoxwork@...> wrote

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

My guess is that your web server user id is not set up to find the
Python modules. You probably need the admin to do some
web config

But that is just a guess.

Alan G.

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Parent Message unknown Re: CGI Script Fails on import cgi

by Alan Gauld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Please use ReplyAll when replying to the list.
And please do not hijack other threads, it confuses 
threaded mail tools/newsreaders.


From: Keshav Inderjeet <vick_keshav@...>
To: alan.gauld@...
Sent: Monday, 9 November, 2009 16:10:30
Subject: RE: [Tutor] CGI Script Fails on import cgi


> In fact these codes will work just on C but I need them to work on python. 
> Is there any way to convert em??

Not automatically, you need to translate them into Python yourself. 
The good news is that its probably going to be shorter than the C code.

But we won't do it for you, we will help you to do it for yourself.

How much Python do you know?
Did you try to translate it? How far did you get?
What happened? What is preventing you from fixing it?

Alan G

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor