GAE 500错误:描述符'capitalize'需要'str'对象,但收到'NoneType'Traceback

时间:2012-06-10 19:39:19

标签: google-app-engine traceback nonetype

Python的新手,我在cgitb.enable()的开发中遇到了这个错误,但是当cgitb.enable()被禁用时,它不会阻止应用程序运行并且没有错误。但是我的应用程序在上传到appengine时会收到服务器错误。 string是表单中的文本值,当页面加载时当然是空的:<p>First Name: <input type="text" name="name"/></p>

<type 'exceptions.TypeError'>A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred. 
/var/www/cgi-bin/index.py in ()
     45 elif mood == "good":
     46     print "In the zone, %s!" % str.capitalize((name))
     47 else:
     48     print "%s, possibilities await!" % str.capitalize((name))
     49  builtin str = <type 'str'>, str.capitalize = <method 'capitalize' of 'str' objects>, name = None

<type 'exceptions.TypeError'>: descriptor 'capitalize' requires a
'str' object but received a 'NoneType'
      args = ("descriptor 'capitalize' requires a 'str' object but received a 'NoneType'",)
      message = "descriptor 'capitalize' requires a 'str' object but received a 'NoneType'"

提前感谢此方向......我猜测当页面加载在if / elif语句中使用str.capitalize引发错误时空白名称值...并且如果/ elif语句只需要运行表单提交后,但我不知道该怎么做,所以请指教。谢谢。

编辑,这适用于捏 ...

  

elif mood ==“good”and name!=“”:

0 个答案:

没有答案