I am a beginner SQLite user and has run into some trouble, hoping to find someone who could help.
I am trying to read some data out of a database, put it into a variable in python and print it out onto a HTML page.
The table inside the database is calle “Status”, it contains two columns “stamp” and “messages”. “stamp is an INT containing a time stamp, and “messages” contains a TEXT.
@cherrypy.expose
def comment(self, ID = None):
con = lite.connect('static/database/Status.db')
output = ""
with con:
cur = con.cursor()
cur.execute("SELECT * FROM Status WHERE stamp = ?", (ID,))
temp = cur.fetchone()
output = temp[0]
comments = self.readComments(ID)
page = get_file(staticfolder+"/html/commentPage.html")
page = page.replace("$Status", output)
The error I am getting reads:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/cherrypy/_cprequest.py", line 606, in respond
cherrypy.response.body = self.handler()
File "/usr/lib/pymodules/python2.7/cherrypy/_cpdispatch.py", line 25, in __call__
return self.callable(*self.args, **self.kwargs)
File "proj1base.py", line 184, in comment
page = page.replace("$Status", output)
TypeError: expected a character buffer object
I was wondering if anyone could help me clarify what a character buffer object is, and how do i use one in order for my code to work?
Replace “character buffer” by “string” for starters. (There are more types exposing the “buffer protocol” in Python, but don’t bother with them for now.) Most likely,
outputended up not being a string. Log its type in the line before the error.