Error setting env thru subprocess.call to run a python script on a remote linux machine
        Posted  
        
            by 
                John Smith
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by John Smith
        
        
        
        Published on 2012-11-02T22:39:47Z
        Indexed on 
            2012/11/02
            23:00 UTC
        
        
        Read the original article
        Hit count: 364
        
I am running a python script on a windows machine to invoke another python script on a remote linux machine. I am using subprocess.call with ssh to do this, like below:
    subprocess.call('ssh -i <identify file> username@hostname python <script_on_linux_machine>') and this works fine.
However, if I want to set some environment variables, like below:
    subprocess.call('ssh -i <identify file> username@hostname python <script_on_linux_machine>', env={key1:value1}) it fails. 
I get the following error:
    ssh_connect: getnameinfo failed
    ssh: connect to host <hostname> port 22: Operation not permitted
    255
I've tried splitting the ssh commands into list and passing. Didn't help. 
I've tried to run other 'local'(windows) commands thru subprocess.call() and tried setting the env. It works fine. 
I've tried to run other commands(such as ls) on the remote linux machine. Again, subprocess.call() works fine, as long as I don't try to set the environment.
What am I doing wrong? Would I be able to set the environment for a python script on a remote machine? Any help will be appreciated.
© Stack Overflow or respective owner