Skip to content Skip to sidebar Skip to footer

"typeerror: 'nonetype' Object Is Unsubscriptable" While Using Fetchone()[0]

I'm having an issue with fetchone() function on the sqlite3 lib object connect: I do a query that might not always return a value; Check if it returned a value; In case it returns

Solution 1:

I believe the mistake you are making is that second call to fetchone(), which almost by definition can only be called once on a cursor that has executed a query returning a single row. Try saving the result and using the saved value rather than calling fetchone() twice without executing a second query. The first call exhausts the result set, so the second one returns None.

fetchone returns a single row, so fetchone()[0] gives you the first (and in this case the only) column from that row. but only when fetchone is actually returning a row!

Post a Comment for ""typeerror: 'nonetype' Object Is Unsubscriptable" While Using Fetchone()[0]"