By Pawankumar Dubey


2018-01-19 06:43:12 8 Comments

I am making ssh connect to my IP address using paramiko and then i do execute certain commands in the loop. Previously this worked fine but now this throw exception

logging.basicConfig()
paramiko_logger = logging.getLogger("paramiko.transport")
paramiko_logger.disabled = True
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ipaddress = '169.254.30.39'
ssh.connect(ipaddress, port=22, username='root', password='')

Traceback (most recent call last):
  File ".\Audio_connect.py", line 100, in <module>
    Audio_connect_class('43210')
  File ".\Audio_connect.py", line 10, in __init__
    self.getreorderedzip(reorder)
  File ".\Audio_connect.py", line 34, in getreorderedzip
    self.execute(zip(newinput,newtestcasenames))
  File ".\Audio_connect.py", line 44, in execute
    ssh.connect(ipaddress, port=22, username='root', password='')
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 392, in connect
    t.start_client(timeout=timeout)
  File "C:\Python27\lib\site-packages\paramiko\transport.py", line 545, in start_client
    raise e
RuntimeError: sys.path must be a list of directory names

When i print sys.path this print my folderlocation in which my file is, whereas i know sys.path usually prints list of all dependency folder. I tried almost everything and went through already asked queries on stackoverflow but nothing has helped me.

*****EDIT******** Working Code

import paramiko, os, sys, time
import Audio_connect_Input
from LogFille import writelogfile

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('169.254.30.39', port=22, username='root', password='')

channel = ssh.invoke_shell()

channel_data = str()
MainConnectionId= str()
isError = False

input =[
       Audio_connect_Input.A,
        Audio_connect_Input.B,
        Audio_connect_Input.C,
        Audio_connect_Input.D,
        Audio_connect_Input.E
        ]
testcaseNames = [
                'A',
                'B',
                'C',
                'D',
                'E'
                ]

key = str()
elem = str()

#while True:
for (x,name) in zip(input,testcaseNames):
 .... Execution steps...

sys.path result 
C:\XYZ_CLI\cli_testexecutions
E:\python27
C:\WINDOWS\SYSTEM32\python27.zip
E:\Python27\DLLs
E:\Python27\lib
E:\Python27\lib\plat-win
E:\Python27\lib\lib-tk
E:\Python27\lib\site-packages

******Non Working Code******

import paramiko, os, sys, time
from LogFille import writelogfile
import logging
import Audio_connect_Input

class Audio_connect_class(object):
    def __init__(self, reorder):
        print '__init___ ', sys.path
        self.getreorderedzip(reorder)

    def getreorderedzip(self, reorder):
        print ''

        input =[
           Audio_connect_Input.A,
            Audio_connect_Input.B,
            Audio_connect_Input.C,
            Audio_connect_Input.D,
            Audio_connect_Input.E
            ]
        testcaseNames = [
                    'A',
                    'B',
                    'C',
                    'D',
                    'E'
                    ]

        newinput = []
        newtestcasenames = []
        for idx in reorder:
            newinput.append(input[int(idx)])
            newtestcasenames.append(testcaseNames[int(idx)])
        self.execute(zip(newinput,newtestcasenames))

    def execute(self, received_zip):
        logging.basicConfig()
        paramiko_logger = logging.getLogger("paramiko.transport")
        paramiko_logger.disabled = True
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        ipaddress = '169.254.30.39'
        ssh.connect(ipaddress, port=22, username='root', password='')

        channel = ssh.invoke_shell()

        channel_data = str()
        MainConnectionId= str()
        isError = False

        key = str()
        elem = str()

        #while True:
        for (x,name) in received_zip:
            ****Execution Steps*****

sys.path result 
C:\XYZ_CLI\cli_testexecution_as_class

Both filename are same bur kept in different folder.

1 comments

@Pawankumar Dubey 2018-01-19 10:31:19

Okay so after digging a lot of time in to the hassle I figured out that from LogFille import writelogfile was internally performing os.sys.path = os.getcwd() which was changing sys.path making it exception for paramiko to handle while accessing libraries at runtime.

Related Questions

Sponsored Content

36 Answered Questions

[SOLVED] How to make a flat list out of list of lists?

35 Answered Questions

[SOLVED] How do I list all files of a directory?

  • 2010-07-08 19:31:22
  • duhhunjonn
  • 2718844 View
  • 3048 Score
  • 35 Answer
  • Tags:   python directory

33 Answered Questions

[SOLVED] How do I check if a list is empty?

  • 2008-09-10 06:20:11
  • Ray Vega
  • 1909469 View
  • 2918 Score
  • 33 Answer
  • Tags:   python list is-empty

28 Answered Questions

[SOLVED] Finding the index of an item given a list containing it in Python

  • 2008-10-07 01:39:38
  • Eugene M
  • 2854004 View
  • 2394 Score
  • 28 Answer
  • Tags:   python list

25 Answered Questions

[SOLVED] How can I safely create a nested directory in Python?

24 Answered Questions

[SOLVED] Difference between append vs. extend list methods in Python

28 Answered Questions

[SOLVED] How to concatenate two lists in Python?

  • 2009-11-12 07:04:09
  • y2k
  • 1558030 View
  • 1785 Score
  • 28 Answer
  • Tags:   python list

15 Answered Questions

[SOLVED] Find current directory and file's directory

  • 2011-02-28 01:51:21
  • John Howard
  • 1975770 View
  • 1612 Score
  • 15 Answer
  • Tags:   python directory

1 Answered Questions

[SOLVED] authentication exception in paramiko

  • 2017-06-12 12:39:54
  • mydigi
  • 474 View
  • 1 Score
  • 1 Answer
  • Tags:   python paramiko

18 Answered Questions

[SOLVED] How to clone or copy a list?

Sponsored Content