[Ironpython-users] Connecting to ssh through Paramiko from c# throws exception TypeError: expected _counter, got _counterStarting ...

Naga Jamini Mungara njmungara at pixentiasolutions.com
Mon Sep 1 13:39:05 CEST 2014


Hi Team,



>From our c# application, we are executing python (IronPython Version-2.7,
32-bit) scripts with the help of clrzmq (Version-2.2.5, 32-bit) for inter
process communication. From that python scripts we were trying to connect
to SSH using paramiko which is of 32-bit  (Application runs in Any CPU
mode).



We were able to run the python scripts from command prompt and connecting
to SSH without any issues, but when we try to run the same from our c#
application it is throwing us the following exception.



Traceback (most recent call last):

  File "C:\..\..\..\Sample.py", line 39, in <module>

  File "C:\..\..\...\ Sample1.py", line 674, in __init__

  File "C:\Program Files (x86)\IronPython
2.7\Lib\site-packages\paramiko\client.py", line 242, in connect

  File "C:\Program Files (x86)\IronPython
2.7\Lib\site-packages\paramiko\transport.py", line 346, in start_client

TypeError: expected _counter, got _counterStarting ...



The python code which we have written is as follows:



__Sample.py:__

....

sys.path.append ("C:\\Program Files (x86)\\IronPython 2.7\\Lib")

....

sys.path.append ("C:\\..\\..\\SampleLibrary")

import Sample1

d = Sample1.d

.....

print 'Initiating Paramiko interface'

print 'Starting ...'

.........

sshSession = Sample1.SampleSSH ('190.167.22.3', 'abc', 'abc')

theResult = sshSession.SSHCommand('...')

print "The result ..."

print theResult



__Sample1.py :__

from array import *

sys.path.append("C:\\Program Files (x86)\\IronPython 2.7\\clrzmq.2.2.5")

clr.AddReference("clrzmq.dll")



from System.Text import Encoding

import ZMQ as zmq

from ZMQ import SocketType



sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib\site-packages")

sys.path.append("C:\Program Files (x86)\IronPython 2.7\DLLs")

clr.AddReference("IronPyCrypto.dll")

import paramiko

......

class SampleSSH:

  def __init__(self, IP, user, password):

    self.ssh = paramiko.SSHClient()

    self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    self.ssh.connect(IP, username=user,

        password=password)

    self.retStr=''

    self.sessionBuffer=''

 def SSHCommand( self, Command):

    self.retStr=''

    d.debug( 'SSHCommand: ' + Command )

    stdin,stdout,stderr = self.ssh.exec_command(Command)

    for line in stdout.readlines():

        d.debug( line  )

        self.retStr = self.retStr + line

    self.sessionBuffer = self.sessionBuffer + 'Command: ' + Command + '\r\n'


    self.sessionBuffer = self.sessionBuffer + self.retStr + '\r\n'

    return self.retStr



Could you please suggest us the better approach to be followed to resolve
this issue?



Thanks,

Jamini Mungara.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140901/9de18e86/attachment.html>


More information about the Ironpython-users mailing list