Archived
This forum has been archived. Please start a new discussion on GitHub.
My first Python code fails with dictionaries
in Help Center
Hello!
I'm doing some test codes with Python. I've created a slice definition (Ice_bindings.ice):
So, I've created a the server code (Ser.py):
and the client (Cli.py):
When I run the client I get this error:
and the server says:
What I'm mistaking?
Thank you in advance.
I'm doing some test codes with Python. I've created a slice definition (Ice_bindings.ice):
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):
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):
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:
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:
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.
0
Comments
-
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: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.0 -
OK! That was the problem!
Thank you!0