In the below script a simple webserver is created and there is a class that should sends GET data to a sqlite3 database.
import SimpleHTTPServer
import SocketServer
import sqlite3
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
class DBLoggingHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super(DBLoggingHandler, self).__init__(*args, **kwargs)
self.db = sqlite3.connect('/home/cron1admin/crazysean/crazysean.db')
def do_GET(self):
self.db.execute("INSERT INTO crazysean (command, vers, path) VALUES (?, ?, ?)",
(self.command, self.request_version, self.path))
self.db.commit()
return super(DBLoggingHandler, self).do_GET()
DBLoggingHandler()
The webserver portion of the script works properly. I am seeing GET data in my terminal output. However, nothing is being written to the crazysean table that I created in the db. Do you see anything wrong with my script or is it likely something else?
Code has been changed to reflect changes that I have made, but it is still not writing to the db.
UPDATED CODE:
import SimpleHTTPServer
import SocketServer
import sqlite3
PORT = 8000
class DBLoggingHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, *args, **kwargs)
self.db = sqlite3.connect('/home/cron1admin/crazysean/crazysean.db')
def do_GET(self):
self.db.execute("INSERT INTO crazysean (command, vers, path) VALUES (?, ?, ?)",
(self.command, self.request_version, self.path))
self.db.commit()
return super(DBLoggingHandler, self).do_GET()
Handler = DBLoggingHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
commit()on the connection.CREATE TABLE crazyseansomewhere in that database? (2) Is Are you trying to keep the same database open in this program and also in an editor (thesqlite3command-line, a GUI editor, whatever) at the same time?SELECT * FROM crazyseanand still nothing. I guess the db is always open, correct? I never close it in the script. Would this cause issues?