paramiko / paramiko

The leading native Python SSHv2 protocol library.
http://paramiko.org
GNU Lesser General Public License v2.1
9.13k stars 2k forks source link

ProxyCommandFailure:'An operation was attempted on something that is not a socket' #1271

Open budikols opened 6 years ago

budikols commented 6 years ago

from error log:

File "C:\Users\d717090\AppData\Local\Continuum\anaconda3\lib\site-packages\paramiko\proxy.py", line 106, in recv raise ProxyCommandFailure(' '.join(self.cmd), e.strerror)

ProxyCommandFailure: ('ssh -xaW 172.16.180.100:22 jumphost', 'An operation was attempted on something that is not a socket')

trying to use netmiko with a jump host to ssh to 172.16.180.100 but receive this error above.

pehruby commented 6 years ago

I have the same issue. It looks like it is Windows related. The same code works well under Linux.

import os
import sys
import paramiko

def test_client(host_name):
    conf = paramiko.SSHConfig()
    conf.parse(open(os.path.expanduser('~/.ssh/config')))
    host = conf.lookup(host_name)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    client.connect(
        host['hostname'], username='cisco',
        password='cisco',
        sock=paramiko.ProxyCommand(host.get('proxycommand'))
    )
    stdin, stdout, stderr = client.exec_command('sh users')
    print(stdout.read())

if __name__ == '__main__':
    test_client('10.255.0.6')
PS C:\Users\pehruby\Documents\Vagrant\netbuntu\ansible-cpoj\netmiko-test> py -3 .\paramikoproxytest.py
Exception: ('ssh -o StrictHostKeyChecking=no jumphost nc 10.255.0.6 22', 'Došlo k pokusu o operaci s něčím, co není soket')
Traceback (most recent call last):
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\proxy.py", line 97, in recv
    r, w, x = select([self.process.stdout], [], [], select_timeout)
OSError: [WinError 10038] Došlo k pokusu o operaci s něčím, co není soket

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 1966, in run
    self._check_banner()
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 2138, in _check_banner
    buf = self.packetizer.readline(timeout)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\packet.py", line 367, in readline
    buf += self._read_timeout(timeout)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\packet.py", line 561, in _read_timeout
    x = self.__socket.recv(128)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\proxy.py", line 109, in recv
    raise ProxyCommandFailure(" ".join(self.cmd), e.strerror)
paramiko.ssh_exception.ProxyCommandFailure: ('ssh -o StrictHostKeyChecking=no jumphost nc 10.255.0.6 22', 'Došlo k pokusu o operaci s něčím, co není soket')

Traceback (most recent call last):
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\proxy.py", line 97, in recv
    r, w, x = select([self.process.stdout], [], [], select_timeout)
OSError: [WinError 10038] Došlo k pokusu o operaci s něčím, co není soket
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 2093, in run
    self.sock.close()
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\proxy.py", line 112, in close
    os.kill(self.process.pid, signal.SIGTERM)
PermissionError: [WinError 5] Přístup byl odepřen

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File ".\paramikoproxytest.py", line 44, in <module>
    test_client('10.255.0.6')
  File ".\paramikoproxytest.py", line 38, in test_client
    sock=paramiko.ProxyCommand(host.get('proxycommand'))
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\client.py", line 397, in connect
    t.start_client(timeout=timeout)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 587, in start_client
    raise e
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 1966, in run
    self._check_banner()
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 2138, in _check_banner
    buf = self.packetizer.readline(timeout)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\packet.py", line 367, in readline
    buf += self._read_timeout(timeout)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\packet.py", line 561, in _read_timeout
    x = self.__socket.recv(128)
  File "C:\Users\pehruby\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\proxy.py", line 109, in recv
    raise ProxyCommandFailure(" ".join(self.cmd), e.strerror)
paramiko.ssh_exception.ProxyCommandFailure: ('ssh -o StrictHostKeyChecking=no jumphost nc 10.255.0.6 22', 'Došlo k pokusu o operaci s něčím, co není soket')

When I run a similar command directly from cmd/powershell it works fine

PS C:\Users\pehruby\Documents\Vagrant\netbuntu\ansible-cpoj\netmiko-test> ssh -o ProxyCommand='ssh -o StrictHostKeyCheck
ing=no jumphost nc 10.255.0.6 22' cisco@10.255.0.6
C
**************************************************************************
* IOSv is strictly limited to use for evaluation, demonstration and IOS  *
* education. IOSv is provided as-is and is not supported by Cisco's      *
* Technical Advisory Center. Any use or disclosure, in whole or in part, *
* of the IOSv Software or Documentation to any third party for any       *
* purposes is expressly prohibited except as otherwise authorized by     *
* Cisco in writing.                                                      *
**************************************************************************
Password:
C
**************************************************************************
* IOSv is strictly limited to use for evaluation, demonstration and IOS  *
* education. IOSv is provided as-is and is not supported by Cisco's      *
* Technical Advisory Center. Any use or disclosure, in whole or in part, *
* of the IOSv Software or Documentation to any third party for any       *
* purposes is expressly prohibited except as otherwise authorized by     *
* Cisco in writing.                                                      *
**************************************************************************
access1#
pehruby commented 6 years ago

Duplicit #512