4

Is there any possibility to allow xmlrpc extensions (datatype long int) for the Python simplexmlrpc server?

The client uses Apache xmlrpc, which allows 8 byte integers.

Basically, I'm using the example code with this function to test it:

def FcnRLong():
    x=8000000000L
    return x

which results in this error:

Java exception occurred:
org.apache.xmlrpc.XmlRpcException: <type 'exceptions.OverflowError'>:long int exceeds XML-RPC limits

Any ideas? Is there any xmlrpc server for Python 2.7 which supports long int?

nikolas
  • 8,707
  • 9
  • 50
  • 70
Daniel
  • 36,610
  • 3
  • 36
  • 69

1 Answers1

10

The second line in the following snippet changes the marshalling for long integers to emit <i8> instead of <int>. Yes, it's not too pretty, but should work and fix the problem.

>>> import xmlrpclib
>>> xmlrpclib.Marshaller.dispatch[type(0L)] = lambda _, v, w: w("<value><i8>%d</i8></value>" % v)
>>> xmlrpclib.dumps((2**63-1,))
'<params>\n<param>\n<value><i8>9223372036854775807</i8></value></param>\n</params>\n'
jhermann
  • 2,071
  • 13
  • 17
  • Yes, this is exactly what I was looking for. Thanks! You'll get the bounty in 4 hours ;) – nikolas Sep 18 '13 at 07:48
  • Perfect simple solution. Some clients require `"%d"`, some `"%d"`, most accept both. – Daniel Oct 16 '13 at 21:54
  • 1
    Isn't it cleaner to simply use `long` instead of `type(0L)` ? – saeedgnu Jun 09 '15 at 04:38
  • In my case, sending the number as a string instead of trying to send it as an integer(convert to string and remove suffix 'L') worked, but I guess it depends on the implementation. Just think it's worth trying as it's a clearer solution. – Arthur.V Aug 13 '16 at 18:36
  • This works when I use `xmlrpclib.dumps()` as in the given example, but I still get the error when using `xmlrpclib.ServerProxy`. – Sam Kauffman Jan 23 '19 at 20:29