sys.path必须是paramiko的目录名列表?

时间:2018-01-19 06:43:12

标签: python paramiko

我正在使用paramiko将ssh连接到我的IP地址,然后我在循环中执行某些命令。以前这个工作正常,但现在抛出异常

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

当我打印sys.path时,打印我的文件夹所在的文件夹位置,而我知道sys.path通常打印所有依赖文件夹的列表。我尝试了几乎所有的东西,并通过stackoverflow上的已经问过的查询,但没有任何帮助我。

***** ******** EDIT 工作守则

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

******非工作代码******

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

两个文件名都保存在不同的文件夹中。

1 个答案:

答案 0 :(得分:0)

好的,所以在花了很多时间讨论麻烦后我发现select Name,Dateadded from table where Convert(date, dateadded) = '2009-12-11' 在内部执行from LogFille import writelogfile正在改变sys.path,这使得paramiko在运行时访问库时处理异常。