Results 1 to 3 of 3

Thread: My first Python code fails with dictionaries

  1. #1
    Anhur is offline Registered User
    Name: Luigi Paioro
    Organization: INAF - IASF Milan
    Project: MIMA prototype
    Join Date
    Jun 2006
    Posts
    8

    My first Python code fails with dictionaries

    Hello!

    I'm doing some test codes with Python. I've created a slice definition (Ice_bindings.ice):
    Code:
    module fase {
      module bindings {
        module logging {
          dictionary<string, string> Message;
          interface LoggingServer {
            void NewMessage(Message msg);
            void log(Message msg);
          };
        };
      };
    };
    So, I've created a the server code (Ser.py):
    Code:
    import sys, traceback, Ice
    
    Ice.loadSlice("Ice_bindings.ice")
    import fase.bindings.logging
    
    class LoggingServer(fase.bindings.logging.LoggingServer):
        def log(self, msg):
            print msg
    
    status = 0
    ic = None
    
    try:
        ic = Ice.initialize(sys.argv)
        adapter = ic.createObjectAdapterWithEndpoints(
            "LoggingServerAdapter", "default -p 10000")
        logger = LoggingServer()
        adapter.add(logger, Ice.stringToIdentity("LoggingServer"))
        adapter.activate()
        ic.waitForShutdown()
    except:
        traceback.print_exc()
        status = 1
    
    if ic:
        # Clean up
        try:
            ic.destroy()
        except:
            traceback.print_exc()
            status = 1
    
    sys.exit(status)
    and the client (Cli.py):

    Code:
    import sys, traceback, Ice
    
    Ice.loadSlice("Ice_bindings.ice")
    import fase.bindings.logging
    
    status = 0
    ic = None
    
    try:
        ic = Ice.initialize(sys.argv)
        base = ic.stringToProxy("LoggingServer:tcp default -p 10000")
        logger = fase.bindings.logging.LoggingServerPrx.checkedCast(base)
        if not logger:
            raise RuntimeError("Invalid proxy")
        
        logger.log({"pippo":"pluto"})
        
    except:
        traceback.print_exc()
        status = 1
    
    if ic:
        # Clean up
        try:
            ic.destroy()
        except:
            traceback.print_exc()
            status = 1
            
    sys.exit(status)
    When I run the client I get this error:
    Code:
    Traceback (most recent call last):
      File "Cli.py", line 16, in ?
        logger.log({"pippo":"pluto"})
      File "Ice_bindings.ice", line 50, in log
    UnknownException: exception ::Ice::UnknownException
    {
        unknown = exceptions.TypeError: log() takes exactly 2 arguments (3 given)
    }
    and the server says:
    Code:
    Ser.py: warning: dispatch exception: Util.cpp:132: Ice::UnknownException:
    unknown exception:
    exceptions.TypeError: log() takes exactly 2 arguments (3 given)
    identity: LoggingServer
    facet:
    operation: log
    What I'm mistaking?

    Thank you in advance.
    Luigi Paioro
    INAF - Istituto Nazionale di Astrofisica

    IASF Milano
    Via Bassini 15, I-20133 Milano, Italy
    Site : http://www.iasf-milano.inaf.it/

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Hi,

    I believe this is caused by the definition of your "log" servant method. It's missing the "current" parameter. It should be something like the following instead:

    Code:
    class LoggingServer(fase.bindings.logging.LoggingServer):
        def log(self, msg, current=None):
            print msg
    See Section 24.5 and 30.6 in the Ice manual for more information on this "current" parameter.

    Cheers,
    Benoit.

  3. #3
    Anhur is offline Registered User
    Name: Luigi Paioro
    Organization: INAF - IASF Milan
    Project: MIMA prototype
    Join Date
    Jun 2006
    Posts
    8
    OK! That was the problem!

    Thank you!
    Luigi Paioro
    INAF - Istituto Nazionale di Astrofisica

    IASF Milano
    Via Bassini 15, I-20133 Milano, Italy
    Site : http://www.iasf-milano.inaf.it/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 02-05-2007, 08:59 AM
  2. "import Ice" fails in Python 2.4
    By jay in forum Help Center
    Replies: 2
    Last Post: 05-29-2006, 12:12 PM
  3. adapter.find fails with Python
    By hiasl in forum Help Center
    Replies: 4
    Last Post: 01-31-2006, 03:27 PM
  4. Trouble with Python demo code
    By pellis in forum Help Center
    Replies: 1
    Last Post: 02-07-2005, 05:30 PM
  5. make test fails with Python 2.0
    By jmu in forum Bug Reports
    Replies: 0
    Last Post: 02-23-2003, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •