IronLanguages / main

Work for this repo has moved to https://github.com/IronLanguages/ironpython2
1.16k stars 347 forks source link

Paramiko in python script throws exception- TypeError: expected _counter, got _counterStarting ... #1118

Open ironpythonbot opened 9 years ago

ironpythonbot commented 9 years ago

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
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.

Work Item Details

Original CodePlex Issue: Issue 35515 Status: Proposed Reason Closed: Unassigned Assigned to: Unassigned Reported on: Aug 30 at 8:05 AM Reported by: jamini Updated on: Sep 10 at 12:26 AM Updated by: r4ndy

Binary Attachments

output.png

ironpythonbot commented 9 years ago

On 2014-08-31 17:12:52 UTC, paweljasinski commented:

We were able to run the python scripts from command prompt and connecting to SSH without any issues how does your command line looks like?

ironpythonbot commented 9 years ago

On 2014-08-31 17:14:23 UTC, paweljasinski commented:

We were able to run the python scripts from command prompt and connecting to SSH without any issues

how does your command line looks like?

ironpythonbot commented 9 years ago

On 2014-09-01 15:02:29 UTC, jamini commented:

Hi

We are running the scripts from command line as follows :

C:\Program Files (x86)\IronPython 2.7> ipy.exe -X:Frames C:.........\Sample.py

I'm attaching the output for above execution, please find it.

Thanks, Jamini Mungara.

ironpythonbot commented 9 years ago

On 2014-09-02 05:08:52 UTC, paweljasinski commented:

I am afraid I have no simple answer for your question. I would look for differences between command line run and embedded run. Some candidates:

sys.path permissions/credentials (who runs it) current working directory Another line of attack is to find out more about the exception. Rudimentary check in paramiko reveals that the origin is obfuscated. Try to find the place where it is raised.

Something puzzling, I can find _counter but see no traces of _counterStarting. I checked paramiko and ironpycrypto.

ironpythonbot commented 9 years ago

On 2014-09-02 12:11:04 UTC, jamini commented:

Hi,

Sorry I forgot to say this, the output "Starting" which was a simple print statement was appended to that _counter. So it appears as _counterStarting.

Thanks, Jamini Mungara.

ironpythonbot commented 9 years ago

On 2014-09-02 19:00:36 UTC, jamini commented:

We added a Microsoft.scripting.debugging.dll to our solution to debug the python scripts. While debugging them we found self.active property is getting false in client.py file in paramiko when executing ssh connect statement. There we are getting that exception.

__TypeError:Expected counter, got counter.

The stack trace for that exception is as follows : at Microsoft.Scripting.Interpreter.MethodInfoCallInstruction.InvokeWorker(Object[] args) at Microsoft.Scripting.Interpreter.MethodInfoCallInstruction.Invoke(Object[] args) at Microsoft.Scripting.Interpreter.MethodInfoCallInstruction.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) at Microsoft.Scripting.Interpreter.DynamicInstruction7.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) at NHRTest1$2.init$54(PythonFunction $function, Object self, Object IP, Object user, Object password) in C:\xxtws\trunk\NHRLibrary\NHRTest1.py:line 678 at IronPython.Runtime.FunctionCaller4.Call4(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) at IronPython.Runtime.Method.MethodBinding3.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0, T1 arg1, T2 arg2) at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) at Microsoft.Scripting.Interpreter.DynamicInstruction6.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) at $1.(CodeContext $globalContext, FunctionCode $functionCode) in C:\xxtws\trunk\Server\Test3.py:line 55 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at IronPython.Compiler.PythonScriptCode.Run(Scope scope) at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope) at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope) at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path) at Microsoft.Scripting.Hosting.ScriptRuntime.ExecuteFile(String path)

Hope this information may help you to suggest us the approach to be followed.

ironpythonbot commented 9 years ago

On 2014-09-04 21:29:31 UTC, paweljasinski commented:

what is inside C:\xxtws\trunk\NHRLibrary\NHRTest1.py around line 678?