TypeError: cannot concatenate 'str' and 'NoneType' objects

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nandhu678
    New Member
    • Sep 2010
    • 1

    TypeError: cannot concatenate 'str' and 'NoneType' objects

    Code:
    for district in query:
    			self.response.out.write('<tr><td bgcolor="#ffffff" style="font-family:arial;font-size:12px">')
    			self.response.out.write(district.Dis_Id)
    			self.response.out.write('</td><td bgcolor="#ffffff" style="font-family:arial;font-size:12px">')
    			self.response.out.write(district.Dis_Name)
    			self.response.out.write('</td><td bgcolor="#ffffff" style="font-family:arial;font-size:12px"><a href="#"onclick="editdistrict(\''+district.Dis_Id+'\');">Edit</a>/<a href="#"onclick="districtdelete(\''+district.Dis_Id+'\');">Delete</a>')

    Error:::

    Code:
    Traceback (most recent call last):
      File "D:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
        handler.post(*groups)
      File "D:\Documents and Settings\purnachandra\Desktop\duplicate\cyberabadpolice.py", line 1102, in post
        self.response.out.write('</td><td bgcolor="#ffffff" style="font-family:arial;font-size:12px"><a href="#"onclick="editdistrict(\''+district.Dis_Id+'\');">Edit</a>/<a href="#"onclick="districtdelete(\''+district.Dis_Id+'\');">Delete</a>')
    TypeError: cannot concatenate 'str' and 'NoneType' objects
    Last edited by Markus; Sep 20 '10, 11:55 AM. Reason: Added [code] tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Please see: http://bytes.com/topic/python/answer...netype-objects

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Apparently the district attribute Dis_Id has no value. The NoneType object is accessed through the built-in name None. Test for a value before attempting the string addition to avoid the error.

      Comment

      Working...