Jim Gallacher
jpg at jgassociates.ca
Fri Mar 31 07:18:05 EST 2006
Graham Dumpleton wrote: > Remember to keep followups on mailing list. :-) > > A few comments on code: > > On 31/03/2006, at 3:35 PM, Alberto Ruiz wrote: > >> I added debug code in my Python script that writes to a file at >> different stages of the script. The script executes successfully >> without any errors, and my debug writes show up fine in the debug file. >> In any case here is a snippet of my script: >> >> global DB >> import sys >> sys.path.append('/home/john/www/mydomain.com') > > > You shouldn't append to sys.path explicitly in modules because every > time the module is reloaded, it will be extended, thus growing and > growing the path with the same directory. > >> import DBconnectpropman >> import ZWF >> reload(ZWF) > > > Huh???? > >> import time,random,string >> global DATEBOX >> from mod_python import Cookie >> >> def index (req,LLRuser='',LLRpw=''): >> debugfile = open("/home/john/www/mydomain.com/debug.txt", "a") >> debugfile.write("Begining of index function\n") >> global R; R=req; R.content_type="text/html" > > > You should not store the request object in a global variable. If you > ever move > to mod_python 3.X and use a multithreaded MPM it will break as multiple > threads may execute within the same module as the same time. > >> cur=DBconnectpropman.DB.cursor() >> sidrefreshing=0 >> ZWF.R=R >> global SID;SID='' >> global UID;UID='' >> cookies = Cookie.get_cookies(R, Cookie.MarshalCookie, >> secret='LLR14222222') >> if LLRuser!='' and LLRpw!='': # login attempt >> if string.find(LLRuser,"@")!=-1: #client login attempt >> cur.execute("select clientid,name,password from client where >> email='"+LLRuser+"'") >> userrs=cur.fetchone() >> if str(userrs)!='None': >> LLRuser=userrs[1] >> usertable='client' >> else: >> debugfile.write("It is an admin user\n") >> cur.execute("select * from user where name='"+LLRuser+"' and >> password='"+LLRpw+"'") >> userrs=cur.fetchone() >> usertable='user' >> debugfile.write("admin user section.\n") >> if str(userrs)!='None': #login success create session key, >> update user >> record, sett sid cookie >> debugfile.write("userrs is not None.\n") >> SID='' >> for n in range(0,32): >> x=random.randint(48,108) >> if x>57:x+=8 >> if x>90:x+=6 >> SID+=chr(x) >> cookie = Cookie.Cookie('sid', SID); cookie.expires = >> time.time() + >> 36000; Cookie.add_cookie(R, cookie) >> q="update "+usertable+" set SID='"+SID+"' where >> name='"+LLRuser+"' >> and password='"+LLRpw+"'" > > > In mod_python 2.7.X you must flush out the headers before you write any > data > to the response. This is why the order of your stuff is mucked up. > > req.send_http_header() > >> R.write("userq="+q) >> cur.execute(q) >> debugfile.write("Before calling BB.html.\n") >> #R.write("<head><meta http-equiv='refresh' >> content='0;url=BB.html'></head>") >> debugfile.write("AFTER calling BB.html.\n") >> sidrefreshing=1 >> debugfile.write("END of userrs is not None.\n") >> debugfile.write("Before closing debug file\n") >> debugfile.close() >> >> >> I thought that maybe the meta http-equiv was the problem so I commented >> out but I still get the error. >> >> >> >> On Fri, 2006-03-31 at 00:22 -0500, Graham Dumpleton wrote: >> >>> Alberto Ruiz wrote .. >>> >>>> I'm getting a very wierd error when I call my python script. Other >>>> Python scripts seem to work fine but one in particular returns a 500 >>>> server error and the error does not show in the error-log under the >>>> virtual domain that I'm working on but on the main error-log. How can >>>> I >>>> get additional debugging information to find out the problem? >>>> >>>> In the error-log I get the following: >>>> mod_python: (Re)importing mod_python.publisher from None >>> >>> >>> In mod_python 2.7.11, this message possibly doesn't mean much. >>> >>>> When I run my python script I get the following: >>>> >>>> HTTP/1.1 500 Internal Server Error >>>> Date: Fri, 31 Mar 2006 04:46:55 GMT >>>> Server: Apache/1.3.33 (Unix) PHP/4.4.2 mod_python/2.7.11 Python/ 2.4.2 >>>> mod_perl/1.29 >>>> Connection: close >>>> Transfer-Encoding: chunked >>>> Content-Type: text/html; charset=iso-8859-1 >>>> >>>> 262 >>>> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> >>>> <HTML><HEAD> >>>> <TITLE>500 Internal Server Error</TITLE> >>>> </HEAD><BODY> >>>> <H1>Internal Server Error</H1> >>>> The server encountered an internal error or >>>> misconfiguration and was unable to complete >>>> your request.<P> >>>> Please contact the server administrator, >>>> root at mydomain.com and inform them of the time the error occurred, >>>> and anything you might have done that may have >>>> caused the error.<P> >>>> More information about this error may be available >>>> in the server error log.<P> >>>> <HR> >>>> <ADDRESS>Apache/1.3.33 Server at mydomain.com Port 80</ADDRESS> >>>> </BODY></HTML> >>>> >>>> 0 >>> >>> >>> This message in mod_python 2.7.11 with no message in error log >>> generally means that your published function doesn't return anything. >>> >>> Can you post the most minimal publisher function which shows the >>> problem? >>> >>> Graham >>> > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python >
|