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.
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')
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With