DCOracle2 importing problems

Steve Holden sholden at holdenweb.com
Fri Apr 19 21:48:00 EDT 2002


"Hugh" <h.e.w.frater at cs.cf.ac.uk> wrote ...
> I'm importing it in the interactive interpreter using:
> >>> import cgi #runs fine
>
> here's the cgi script:
>
> import DCOracle2
> import md5
> import time
> import base64
> import cgi
> import rotor
>
> connectString = "'scm1hewf/carthage at cs2000'"
>
> def makeSessionId(st):
>   string = ""
>   m = md5.new()
>   m.update('this is a test of the emergency broadcasting system')
>   m.update(str(time.time()))
>   m.update(str(st))
>   return string.replace(base64.encodestring(m.digest())[:-3], '/', '$')
>
> def enc(password):
>   rt = rotor.newrotor('this is a test of the emergency broadcast system',
20)
>   return rt.encrypt(password)
>
> def checkid(id, password):
>   db = DCOracle2.connect(connectString)
>   c = db.cursor()
>   query = "'select password from tblborrower where id = " + formid + "'"
>   c.execute(query)
>   return c.fetchone()
>
> form = cgi.FieldStorage()
> id = form.getvalue('id')
> password = form.getvalue('password')
>
> if (form.getvalue('id')):
>   encrytedpassword = enc(password)
>   sessionId = makeSessionId(id)
>   result = checkid(id, encryptedpassword)

I note you still haven't shown us the error message that you find in the
error log. That would really help.

Python's import mechanism makes use of sys.path, a list of directories to be
scanned for modules. It's entirely possible that the list has different
contents when scritps are executed under your web server.

Note also that you should provide a conformant HTTP data stream when you are
ruinning under the server (though its absence probably isn't causing your
error). Something like

print """Content-Type: text/html

<HTML>
<HEAD><TITLE>Password Changed</TITLE></HEAD>
<BODY>
    <H2>OK, Done!</H2>
</BODY>
</HTML>
"""

Putting this statement in also has the advantage that you can move it higher
and higher in the script until you actualy see some output - then you know
nothing before it is failing. You may need to amke it line 1 in the present
case 8<(

The most recent release of Python (2.2) also has a cgitb module, which is
very helpful in reporting tracebacks. Just put

    import cgitb; cgitb.enable()

at the head of your script and any Python error messages autmagically appear
in the browser.

Hope all this helps. You'll probably find it was something fairly trivial in
the end.

regards
 Steve


--

home: http://www.holdenweb.com/    book: http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list