我想用python和xmlrpc发出请求。
from xmlrpc.client import ServerProxy, datetime
import ssl
import hashlib
hash_object = hashlib.md5(b'USER*PASSWORD')
test = ServerProxy('https://IP/xml-rpc?de.vertico.starface.auth=%s' % hash_object.hexdigest(),
verbose=False, use_datetime=True,
context=ssl._create_unverified_context())
print(test.Queue.getHistoryData({"queueName" : "Hauptgruppe","from" : "20161230T12:59:05", "to" : "20170701T12:59:05"}))
身体需要像这样:
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>Queue.getHistoryData</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>queueName</name>
<value>
<string>testIq</string>
</value>
</member>
<member>
<name>from</name>
<value>
<string>20150701T12:59:05</string>
</value>
</member>
<member>
<name>to</name>
<value>
<string>20160701T12:59:05</string>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
但是我一直收到跟踪错误的结果。我不知道如何解决它。有人可以给我一些帮助吗?
xmlrpc.client.Fault: <Fault 1: 'java.lang.ClassCastException : java.lang.String
cannot be cast to java.util.Date'>
答案 0 :(得分:0)
鉴于错误消息,我怀疑您需要发送<dateTime.iso8601>
标记。尝试发送datetime
个对象:
import datetime
test = ServerProxy(
'https://IP/xml-rpc?de.vertico.starface.auth=%s' % hash_object.hexdigest(),
verbose=False, use_builtin_types=True,
context=ssl._create_unverified_context())
print(test.Queue.getHistoryData({
"queueName": "Hauptgruppe",
"from" : datetime.datetime(2016, 12, 30, 12, 59, 5),
"to": datetime.datetime(2017, 7, 1, 12, 59, 5)}))
请注意,我已转为使用use_builtin_types
,因为use_datetime
已被弃用。