Using xmlrpclib to schedule a remote command

Latest response

Has anyone experienced issues using this Python library? I have to use it with Satellite's API and it constantly gives me problems. For example, when trying to schedule a script remotely I use:

 

import xmlrpclib

earliest_occurrence = xmlrpclib.DateTime()

client.system.scheduleScriptRun(key, id, "root", "root", 600, script, earliest_occurrence)

 

Sometimes it works but most of the time I get this error in response:

 

TypeError: cannot marshal <type 'function'> objects
TypeError: cannot marshal <type 'function'> objects
 
Is there a way around using this xmlrpclib function to schedule the time? I have found this library to be extremely inconsistent. Any help would be greatly appreciated.
 
Thanks!
 

 

Responses

Hello,

In the example you mentioned above I assume that you missed to type the content of the script but in your actual code you already have it defined as a string which contains the actual script.

I tried to execute this couple of times on my test satellite (v5.4.1) and it worked fine.

..snip..
id=<systemID>
earliest_occurrence = xmlrpclib.DateTime()
script="echo test"
result=sc.system.scheduleScriptRun(sk, id, "root", "root", 600, script, earliest_occurrence)
..snip..

Are you facing this error on the same script or there are other scripts using this API call and failing randomly? When it keeps failing have you tried to execute the same remote command through web-interface of the system ?

Paresh

Hello Paresh,

Thank you for the reply :) I believe the issue had/has something do do with how the module was being imported by Python. It seems to be working now and the only thing I changed was I moved the script out of my home directory where the lib files were placed before installing them. After that it appeared that the xmlrpclib  module worked fine. I'm assuming this has to do with the way that modules are imported. Correct me if I'm wrong but I think Python will actually check your immediate directory for your imports first.

Hello Chris,

Yes you are right. It would check the immediate directory first and then move on to other directories as defined/exported (as per sys.path). To check the list you could execute:

import sys
print sys.path

Checking python docs for sys.path "the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH."

So yes likely the libs in your current directory might be leading to the error. Without looking into the actual content of the directory it would be hard to confirm.

Paresh