asynchat/asyncore/oracle "exceptions.TypeError:unpack non-sequence"
Burra
burra at colorado.edu
Tue Jan 22 12:05:32 EST 2002
Hello all,
I really need some help on this one. I am trying to create a sql relay
server which, of course, accepts sql statements, runs them on the
correct database and returns the results to the client.
The problem that I am having is when I add an Oracle connection and
then close one of the client sockets I get this error...
[3] [] []
<socket object, fd=3, family=2, type=1, protocol=0>
[4] [] []
<socket object, fd=4, family=2, type=1, protocol=0>
[] [4] []
[4] [] []
<socket object, fd=4, family=2, type=1, protocol=0>
[] [4] []
[3, 4] [3] []
<socket object, fd=3, family=2, type=1, protocol=0>
error: uncaptured python exception, closing channel
<__main__.securiy_warehouse_server listening :3000 at 0x815c20c>
(exceptions.TypeError:unpack non-sequence
[/usr/local/lib/python2.2/asyncore.py|poll|95]
[/usr/local/lib/python2.2/asyncore.py|handle_read_event|386]
[NewServer.py|handle_accept|15] [NewServer.py|__init__|22])
<socket object, fd=4, family=2, type=1, protocol=0>
error: uncaptured python exception, closing channel
<__main__.securiy_warehouse_receiver connected 10.1.45.246:34256 at
0x817929c> (socket.error:(11, 'Resource temporarily unavailable')
[/usr/local/lib/python2.2/asynchat.py|handle_read|82]
[/usr/local/lib/python2.2/asyncore.py|recv|358])
------------------ My Code -------------------------
import asyncore, asynchat, socket, string, DCOracle2
class warehouse_server (asyncore.dispatcher):
def __init__ (self, host, port):
asyncore.dispatcher.__init__ (self)
# Create our a socket and listen on a port
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.there = (host, port)
self.bind (('', port))
self.listen (15)
def handle_accept (self):
warehouse_receiver (self, self.accept())
class warehouse_receiver (asynchat.async_chat):
channel_counter = 0
def __init__ (self, server, (conn, addr)):
asynchat.async_chat.__init__ (self, conn)
self.set_terminator ('\r\n')
self.buffer = ''
self.server = server
self.id = self.channel_counter
self.channel_counter = self.channel_counter + 1
self.interactive = None
self.prompt = '(query) '
def collect_incoming_data (self, data):
# Put data read from socket to a buffer
self.buffer = self.buffer + data
def found_terminator (self):
# This method is called by asynchronous engine when it finds
# command terminator in the input stream
data = self.buffer
# Reset input buffer
self.buffer = ''
# Handle user command
print '<== (%s) %s' % (self.id, repr(data))
response = self.process_command (data)
# Return message back to user
if response and not response == "close":
self.push (str(response) + '\r\n')
if self.interactive and not response == "close":
self.push (self.prompt)
def process_command(self, data):
line = string.strip(data)
# Make sure request is not empty
if not line:
return None
# Close the connection when the user wants
if line == "exit" or line == "quit":
self.handle_close()
return "close"
# Set the session interactive
if line == "INTERACTIVE":
self.interactive = 1;
return None
db = DCOracle2.connect('username/password')
self.cursor = db.cursor()
try:
self.cursor.execute(line)
return self.cursor.fetchall()
except:
return sys.exc_value[1]
self.cursor.close()
db.close()
def handle_close (self):
if self.interactive:
self.push ("Goodbye\n")
self.close()
if __name__ == '__main__':
import sys
if len(sys.argv) < 3:
print 'Usage: %s <server-host> <server-port>' % sys.argv[0]
else:
server = warehouse_server (sys.argv[1], string.atoi
(sys.argv[2]))
# Start the select() I/O multiplexing loop
asyncore.loop()
Please email me directly if you have a solution. Thanks.
burra at colorado.edu
More information about the Python-list
mailing list