Reputation: 51
I'm trying to get xmlrpc to work over ssh so I'm using the paramiko library in python. I can get the connection fine, and even run programs, so my issues aren't the network or installation.
getting the error,
AttributeError: 'Transport' object has no attribute 'request'
while calling the line result = xmlrpc_client.your_method_name()
My server code is very simple:
from xmlrpc.server import SimpleXMLRPCServer
# Create an XML-RPC server
server = SimpleXMLRPCServer(("your_hostname", your_port))
# Register a function that can be called through the XML-RPC server
def your_method_name():
return "hello, world!"
server.register_function(your_method_name)
# Start the XML-RPC server
server.serve_forever()
client code is a bit longer
import paramiko
import xmlrpc.client
# Set the hostname, username, and password for the remote machine
HOSTNAME = "your_hostname"
USERNAME = "username"
PASSWORD=getpass("Enter password:") # robot password
port="someport"
# Create an SSH client
ssh = paramiko.SSHClient()
# Add the remote host's hostname to the known hosts file
ssh.load_system_host_keys()
# Connect to the remote host
ssh.connect(HOSTNAME, username=USERNAME, password=PASSWORD)
# Create an XML-RPC client using the SSH transport
transport = ssh.get_transport()
xmlrpc_client = xmlrpc.client.ServerProxy(f"http://{hostname}:{port}", transport=transport)
# Call an XML-RPC method on the remote host
result = xmlrpc_client.your_method_name()
# Print the result of the XML-RPC call
print(result)
# Close the connection
ssh.close()
getting the error,
AttributeError: 'Transport' object has no attribute 'request'
while calling result = xmlrpc_client.your_method_name()
which calls the xmlrpc/client.py
in that library,
response = self.__transport.request(
1465 self.__host,
1466 self.__handler,
1467 request,
1468 verbose=self.__verbose
1469 )
So there seems to be some difference between the transport object in the xmlrpc.client and the one returned from the ssh object in paramiko? Anyone have an example where they get this to work?
thanks!
Upvotes: 0
Views: 308