django – ‘int’ object has no attribute ‘keys’

Being new to Django, sometimes I face interesting problems. If it is very late and you are very tired, It may not always be easy to see the problem looking at the displayed error message like this int’ object has no attribute ‘keys’ error message I got in cursor.execute() method 🙂

This error was thrown on the line below:

cursor.execute(“select col1,col2 from table_name where col3 = %s”, integer_value)

The reason I got this error was that I had provided the integer directly as an argument but according to the documentation the second argument must be a sequence or mapping. Below solved the issue:

cursor.execute(“select col1,col2 from table_name where col3 = %s”, [integer_value])

Hope this helps.
Good Luck,
Serdar

Serdar Osman Onur
I love coding web stuff, learning/applying new technologies and techniques to create things on the internet since 2004. AboutMe G+ twitter
Serdar Osman Onur

@serdarosmanonur

hard work, determination, dedication, patience, consistency, faith
"We forge our bodies in the fire of our will" - Enter the Dragon - 1973 - 3 days ago
Serdar Osman Onur