[mod_python] Does the Request object have a member called 'name'?

Graham Dumpleton grahamd at dscpl.com.au
Mon Apr 3 20:38:04 EDT 2006


Alberto Ruiz wrote ..
> This script used to run fine on a Debian system. This is now on FreeBSD
> with modpython 2.7.11.
> 
> This is what I'm getting:
> 
> !V!:0!!V!:My Property Test!!V!:1234 West!!V!:Orem, UT, 84052!!V!:1!!
> V!:!!V!:!!V!:3!!V!:1!!V!:8!!V!:200!!V!:300!!V!:100!!V!:!!V!:!!V!:!!V!:!!
> V!:!!V!:22!!V!:! Mod_python error: "PythonHandler mod_python.publisher"
> Traceback (most recent call last): File
> "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", line 193,
> in Dispatch result = object(req) File
> "/usr/local/lib/python2.4/site-packages/mod_python/publisher.py", line
> 173, in handler result = apply(object, (), args) File
> "/home/elkmeadowsrental/www/elkmeadowsrentals.com/save.py", line 23, in
> index exclamation=q.name.find("!") AttributeError: 'NoneType' object has
> no attribute 'find'
> 
> 
> On the following code:
> 
> def index (req,t="",id=""):
> 	global R; R=req;R.content_type="text/html"
> 	R.send_http_header()
> 	R.write(" ")
> 	dbcur=DBconnectpropman.DB.cursor()
> 	USER=ZWF.usercheck(R,dbcur)
> 	photo=[]
> 	if USER.auth==1:
> 		tables={};id=0;detailid=0;propid='';custid=''
> 		for q in R.form.list:
> 			if q.name=="res!propertyid":propid=q.value
> 			if q.name=="res!startdate":ressdate=q.value
> 			if q.name=="res!enddate":resedate=q.value
> 			if q.name=="res!customerid":custid=q.value
> 			if q.name==t+"formkey": 
> 				if q.value=="": id="0"
> 				else: id=q.value;
> 			exclamation=q.name.find("!")
> .... more code
> 
> 
> The problem is when calling the last line.  It seems that q.name is not
> defined.  What's wrong? Is this a member method that is implemented in
> newer versions (3.1x)?  How do I implement it in 2.7?  Is the problem
> somewhere else?  What's the best way to troubleshoot the problem?

I have noticed that sometimes a form key name can be none. Not sure
if this was a mod_python 2.7.X specific thing or not, but my forms
code has:

      # Some strange forms can result in fields where the
      # key value is None. Wipe this out just in case this
      # happens as can cause problems later.

      if args.has_key(None):
        del args[None]

You may therefore simply want to ignore case where q.name is None.

Graham


More information about the Mod_python mailing list