1

i want to make a request with python and 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"}))

The body needs to be like this:

<?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>

But i keep getting following error as result. And i dont know how to fix it. Can someone please give me some help?

xmlrpc.client.Fault: <Fault 1: 'java.lang.ClassCastException : java.lang.String
cannot be cast to java.util.Date'>
5
  • Are you certain that the from and to values are supposed to be strings, and that their format is correct? Commented Jan 14, 2017 at 23:31
  • yeah, the body i posted here is the example from the manufacturers wiki. So the python code is correct? Commented Jan 14, 2017 at 23:35
  • Note that the use_datetime flag is obsolete; you want to use the use_builtin_types=True flag. Commented Jan 14, 2017 at 23:35
  • I suspect that they really want <dateTime.iso8601> tags. Try using import datetime and "from": datetime.datetime(2016, 12, 30, 12, 59, 5) and "to": datetime.datetime(2017, 7, 1, 12, 59, 5) (and have use_builtin_types=True set). Commented Jan 14, 2017 at 23:38
  • that did it, thank you very much Commented Jan 14, 2017 at 23:40

1 Answer 1

1

Given the error message, I suspect that you need to send <dateTime.iso8601> tags instead. Try sending datetime objects:

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)}))

Note that I switched to using use_builtin_types as use_datetime is deprecated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.