0

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!

bblais
  • 51
  • 2
  • Based on what do you expect that you can use Paramiko `Transport` object this way with xmlrpc? – Martin Prikryl Dec 07 '22 at 15:58
  • it looks like there is a difference between the transport for ssh and the transport for xmlrpc which is http-based. I saw the code I used somewhere, and it seemed to make sense when I first looked at it, but appearances can be deceiving. I basically want to be able to run xlmrpc, because it is really convenient, but have a remote machine which has network traffic blocked except through ssh. I would settle for another reasonable message passing solution through ssh, but I don't want to have to build an entire communications framework from scratch. – bblais Dec 07 '22 at 17:08
  • Wouldn't port forwarding be the right approach? – Martin Prikryl Dec 07 '22 at 18:13
  • perhaps, but I haven't seen any direct solutions for using port forwarding, or ssh tunneling, or any other such mechanism to get xlm-rpc to work. I don't have control of the router, but I do have admin on the remote machine (which I want to be the xmlrpc server). every tutorial on this that I have read has been overly complicated, or needed router access. – bblais Dec 07 '22 at 21:02
  • This may help you get started: [Setup SSH tunnel with Paramiko to access PostgreSQL](https://stackoverflow.com/q/64291009/850848). It's about database connection. But that makes little difference. The point is that you need to connect your xmlrpc code to the local forwarded port (the way the linked solution comnnects database code to the port). – Martin Prikryl Dec 08 '22 at 07:19

0 Answers0