. Advertisement .
..3..
. Advertisement .
..4..
As advised, I used some code samples in another forum, but it could not improve the problem. My question is the “typeerror: ‘bool’ object is not iterable” in python – How to solve it?
The command line is:
# this uses bottle py framework and should return a value to the html front-end
@get('/create/additive/<name>')
def createAdditive(name):
return pump.createAdditive(name)
def createAdditive(self, name):
additiveInsertQuery = """ INSERT INTO additives
SET name = '""" + name + """'"""
try:
self.cursor.execute(additiveInsertQuery)
self.db.commit()
return True
except:
self.db.rollback()
return False
and the result:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\bottle.py", line 821, in _cast
out = iter(out)
TypeError: 'bool' object is not iterable
What does the message mean? Can you advise me to fix it? If you have other better answers, leave them in the answer box below.
The cause: I think the cause of this error is your code isn’t iterating the value, but the code receiving it is. You can see that on the traceback:
The solution: To solve this problem, you should return an iterable. I recommend either converting the bool to a string (
str(False)
) or enclosing it in a tuple ((False,)
).