0

This question may be silly, but I hate when a programming language does it on me ... so I have the following function:

def udp_server(client=""):
    mutex.acquire()
    try:
        print "Starting server ... "
        server_process = subprocess.Popen("iperf.exe -s -u -i 1 -l 872",
                                          stderr=subprocess.STDOUT,
                                          stdout=subprocess.PIPE)
        print "Server started at ", server_process.pid
        print "Starting the client remotely on %s" % client
        cmd = "cd C:/performance/Iperf && python iperf_udp_client.py -c %s" % client
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.WarningPolicy())
        client.connect(str(client), username=str(config['ssh_user']),
                       password=str(config['ssh_pwd']))
        stdin, stdout, stderr = client.exec_command(cmd)
        print stdout.readlines()
        server_process.kill()
    except Exception, e:
        print e
    finally:
        mutex.release()

config is loaded when the function is loaded ... the values are assigned to a mode.config file, which parses nicely into config (I did test it )

if __name__ == '__main__':
    config = {}
    execfile('C:\performance\mode.config', config)
    main()

When I hardcoded the values into client.connect() it worked nicely, however, when I try to make it in the correct way (using a config file, instead of hardcoding), I get the following error:

Starting the client remotely on 123.456.795
getaddrinfo() argument 1 must be string or None

Of course client is a String: client = config['client']. Could someone please help me? The Python versions is 2.7.5.

10
  • I'm confused, what is your question? Commented Oct 1, 2013 at 21:45
  • 1
    client.connect(str(client), ...) looks rather suspicious. How could the str of a SSHClient instance be useful? Commented Oct 1, 2013 at 21:46
  • 1
    As a side note, using plain string literals and Windows backslash paths together is a recipe for disaster, and even worse if you have lowercase directory and file names. At some point, you're going to try to open a file named 'C:\performance\new.config' Commented Oct 1, 2013 at 21:47
  • Yeah. Also, 123.456.795 is not a valid IP address, double check your config! Python is not "playing a trick" on you... It's pretty much the contrary. Commented Oct 1, 2013 at 21:47
  • 2
    str() is not the issue, the issue is that client is not the string you loaded with client = config['client'], but the SSHClient instance you assigned in the code posted above. Rename one of the two. Commented Oct 1, 2013 at 21:52

2 Answers 2

4

You are overwriting client = config['client'] definition (which is what you have in mind) with client = paramiko.SSHClient(). Rename one of the two variables.

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

Comments

1

You have named two distinct variables both client: the hostname of the client you want to connect to, and the SSHClient instance you are using to connect.

When you do

client.connect(str(client), ...)

you are effectively passing the str of the SSHClient, rather than the hostname of the client. This will result in a failure to resolve the hostname (which probably looks like <SSHClient instance at 0xdeadbeef>).

You can resolve this by renaming one of your variables. For example, you can call the host name hostname instead of client.

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.