5

Messages exchanged between a client and a server using the xmlrpclib using Python 2.6.x creates a type of 'instance' on server side instead of type 'datetime'. On the client side I create a new

updateTime = datetime(year, month, day, hour, minute, second)
print type(updateTime)
print updateTime

results in

<type 'datetime.datetime'>
2015-10-07 10:21:52

when being send, the dictionary looks like this on the client side:

'updateTime': datetime.datetime(2015, 10, 7, 10, 21, 52)

but the incoming dictionary on the server side looks like this:

'updateTime': <DateTime '20151007T10:21:52' at 7f4dbf4ceb90>

printing the type and its string representation looks like this:

<type 'instance'>
20151007T10:21:52

We are using xmlrpclib.ServerProxy but changing use_datetime either to True or False does not make any difference at all.

xmlrpclib.ServerProxy('https://'+rpc_server_addr, allow_none=True, use_datetime=True)

Why is this happening? I expected a tpye 'datetime.datetime' on the receiving side as well.

falc410
  • 85
  • 1
  • 12

2 Answers2

3

You have to convert the xmlrpc.datetime format to a python datetime.datetime object.

The simplest way I have found to transform the object is:

import datetime

my_datetime = datetime.datetime.strptime(str(xmlrpc.datetime), '%Y%m%dT%H:%M:%S')
Eric Rich
  • 507
  • 2
  • 7
2

The use_builtin_types=True works for me. All datetime values have type <class 'datetime.datetime'>.

Without this parameter all datetime were <class 'xmlrpc.client.DateTime'>

rpc = xmlrpc.client.ServerProxy('https://..../', use_builtin_types=True)

The Python3 XML-RPC client documentation says: The obsolete use_datetime flag is similar to use_builtin_types but it applies only to date/time values.

dwich
  • 1,710
  • 1
  • 15
  • 20