[DB-SIG] InternalError

helena bhaska helena_b2001 at yahoo.com
Thu Jan 8 19:19:42 EST 2004


Hi,
I am pretty new to Python database programming, and I
am trying to write a network application, where the
client sends some data to the server, and the server
saves the data into the database.  Client and Server
communicate through sockets, and the server throws the
following error when trying to connect to the
database:

Exception happened during processing of request from
('127.0.0.1', 34516)
Traceback (most recent call last):
  File "/usr/local/lib/python2.3/SocketServer.py",
line 463, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/local/lib/python2.3/SocketServer.py",
line 254, in finish_request
    self.RequestHandlerClass(request, client_address,
self)
  File "/usr/local/lib/python2.3/SocketServer.py",
line 521, in __init__
    self.handle()
  File "test_server.py", line 16, in handle
    db = MySQLdb.Connect(host="localhost",
user="root", passwd="password", db="Purple")
  File
"/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py",
line 63, in Connect
    return apply(Connection, args, kwargs)
  File
"/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py",
line 115, in __init__
    self._make_connection(args, kwargs2)
  File
"/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py",
line 41, in _make_connection
    apply(super(ConnectionBase, self).__init__, args,
kwargs)
InternalError: (-1, 'connection is closed')

here are the chunks of code that attempt to do that:

client code:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'localhost'
port = 8081
s.connect((host, port))
netstring.writens(s, string_to_send)
netstring.writens(s, '')
s.close()

server code:

class
PurpleRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        while 1:
            rq = netstring.readns(self.request)
            if rq == "":
                break
            dt = DateTime.now()
            db = MySQLdb.Connect(host="localhost",
user="root", passwd="password", db="Test")
            c = db.cursor()
            c.execute("""INSERT INTO Commands (Time,
Command) VALUES (%s, %s)""", (str(dt), rq))
            c.close()
            db.close()
purpleServer = SocketServer.ThreadingTCPServer(('',
8081), PurpleRequestHandler)
purpleServer.serve_forever()

The interesting part is that if my server runs on
apache and I connect to it through urllib.urlopen(),
the data is saved into the database just fine.  Is my
MySQL db not configured correctly or something?
Thanks for any pointers!

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus



More information about the DB-SIG mailing list