Skip to content

Instantly share code, notes, and snippets.

@michaeljs1990 michaeljs1990/
Last active Aug 29, 2015

What would you like to do?
Python Sqlite3
import sqlite3
#python 3.4
# This fails with key of site_title
db.execute("SELECT * FROM options WHERE key=?;", (key.encode('utf-8'),))
# This works...
db.execute("SELECT * FROM options WHERE key='site_title';")
# This says I have supplied to many arguments...
db.execute("SELECT * FROM options WHERE key='?';", (key.encode('utf-8'),))

This comment has been minimized.

Copy link
Owner Author

michaeljs1990 commented Aug 19, 2014

Error from first output when i try and access it using fetchone()[0]

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/cherrypy/", line 670, in respond
    response.body = self.handler()
  File "/usr/local/lib/python3.4/dist-packages/cherrypy/lib/", line 217, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/cherrypy/", line 61, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/home/mschuett/python/CherryBlog/CherryBlog/", line 49, in settings
    title = admin.AdminModel.getKey("site_title")
  File "/home/mschuett/python/CherryBlog/CherryBlog/models/", line 63, in getKey
    return cursor.fetchone()[1]
TypeError: 'NoneType' object is not subscriptable

repr output of key 'site_title'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.