This forum has been archived. Please start a new discussion on GitHub.

Python interactive mode - invalid value for element 0

I'm trying to mimic the simple printer example, with my own file:

module Dummy {
struct geo {
int tsn;
string geographicvalue;
string updatedate;
string dummy;
sequence<geo> geolist;
interface geoops {
geolist getgeolist();

Then I tried to create a server and client in two separate python interactive prompts by following the same steps as simpleprinter:

>>> import Ice
>>> i = Ice.initialize()
>>> Ice.loadSlice("")
>>> import Dummy
>>> class geoopsi(Dummy.geoops):
... def getgeolist(self, current=None):
... return (1,"geoval", "1/1/1", "x")
>>> a = i.createObjectAdapterWithEndpoints("geoadapter", "default -p 10000")
>>> s = geoopsi()
>>> a.add(s, Ice.stringToIdentity("crap"))
crap -t:tcp -h -p 10000
>>> a.activate()

>>> import Ice
>>> Ice.loadSlice("")
>>> import Dummy
>>> i = Ice.initialize()
>>> b = i.stringToProxy("crap:default -p 10000")
>>> d = Dummy.geoopsPrx.checkedCast(b)
>>> d.getgeolist()

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "", line 78, in getgeolist

Ice.UnknownException: exception ::Ice::UnknownException
unknown = exceptions.ValueError: invalid value for element 0 of `::Dummy::geolist'

I must be overlooking something simple, can anyone spot the problem?

One odd thing is that I _can_ call the function in the server's cmd window:
>>> s.getgeolist()
(1, 'geoval', '1/1/1', 'x')


  • mes
    mes California
    Welcome to the forum!

    The UnknownException indicates that the problem is in the server, and the error message points out that there's a type mismatch with a sequence element. The problem is in the following code:
    def getgeolist(self, current=None):
        return (1,"geoval", "1/1/1", "x")
    The return value of this operation is declared as a sequence of struct, and Ice maps a Slice struct to a Python class. You need to allocate a geo member like this:
    def getgeolist(self, current=None):
        return (geo(1,"geoval", "1/1/1", "x"),)
    Also notice the extra trailing comma, which is necessary for the parser to treat this as a sequence of one element.

    Take care,
    - Mark
  • mes wrote:
    def getgeolist(self, current=None):
        return (geo(1,"geoval", "1/1/1", "x"),)

    Cool, that worked - although I had to fully qualify geo as Dummy.geo :) Thanks.