problem with "ImportError: No module named..." and sockets

Daniel daniel.watrous at
Tue Sep 30 23:38:19 CEST 2008


I'm trying to build a very simple IPC system.  What I have done is
create Data Transfer Objects (DTO) for each item I'd like to send
across the wire.  I am serializing these using cPickle.  I've also
tried using pickle (instead of cPickle), but I get the same response.

Below is the code.  I'll put the rest of my comments after the code

import SocketServer
import os, sys
newpath = os.path.normpath( os.path.join( __file__, "../../.." ))
sys.path.insert(0, newpath)

from pop.command.UpdateCommand import *
import cPickle

class RequestHandler(SocketServer.StreamRequestHandler):
    "Handles one request to mirror some text."

    def handle(self):

        line = True
        while line:
            line = self.rfile.readline().strip()

        receivedCommand = '\n'.join(total_data)

        newUpdate = cPickle.loads(receivedCommand)
        print type(newUpdate)
        for item in newUpdate.items:
            print str(type(item)) + " with filename: " + item.filename

if __name__ == '__main__':
    import sys
    if len(sys.argv) < 3:
        print 'Usage: %s [hostname] [port number]' % sys.argv[0]
    hostname = sys.argv[1]
    port = int(sys.argv[2])
    server = SocketServer.ThreadingTCPServer((hostname, port),

So I can create the UpdateCommand object on the client, send it across
the wire and I get as far as the line
"newUpdate = cPickle.loads(receivedCommand)",
which when it runs produces the following error:

Traceback (most recent call last):
  File "C:\Python25\lib\", line 464, in
    self.finish_request(request, client_address)
  File "C:\Python25\lib\", line 254, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python25\lib\", line 522, in __init__
  File "C:\Documents and Settings\dwatrous\My Documents\projects\POP
\svn\pop\lib\", line 29, in handle
    newUpdate = cPickle.loads(receivedCommand)
ImportError: No module named UpdateCommand

I import the module at the top of the file, but it doesn't
throw the ImportError until it tries to unpickle.

Please help with any ideas that you have.

More information about the Python-list mailing list