python_paramiko_SSHException Invalid requirement, parse error at
2017-04-15 12:28
471 查看
不加sleep(0.5)会出现SSHException: Invalid requirement, parse error at " '' "问题,原因暂时未知。
结论如下
如果不使用多线程,则不会出现问题
使用多线程一定要sleep(0.2),也就是多个线程之间一定要有时间间隙
执行结果如下,有时候就没有异常,有时候就有 ,我网在也找不到合适的结论
结论如下
如果不使用多线程,则不会出现问题
使用多线程一定要sleep(0.2),也就是多个线程之间一定要有时间间隙
#!/usr/bin/env python import paramiko import threading import sys import time def ssh(host, user, cmd): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() ) pkey_file = '/Users/icq/.ssh/id_rsa' # key = paramiko.RSAKey.from_private_key_file( pkey_file, password='' ) key = paramiko.RSAKey.from_private_key_file( pkey_file, password='' ) try: ssh.connect( hostname=host, username=user, pkey=key, timeout=5 ) except: print 'connection has some problems...' return -1 stdin, stdout, stderr = ssh.exec_command( cmd ) stdout = stdout.read() stderr = stderr.read() if stdout: print '%s: %s' % (host, stdout), ssh.close() else: print '%s: %s' % (host, stderr), ssh.close() if __name__ == '__main__': hosts = ['192.168.31.114', '192.168.31.115', '192.168.31.116', '192.168.31.117'] try: cmd = sys.argv[1] except IndexError: print '%s follow a command must be' % __file__ sys.exit(-1) for host in hosts: t = threading.Thread( target=ssh, args=(host, 'root', 'uptime') ) t.start() time.sleep(0.5) #如果不加此行则会出现下面描述的异常 # ssh(host, 'root', 'uptime')
执行结果如下,有时候就没有异常,有时候就有 ,我网在也找不到合适的结论
192.168.31.116: 11:51:53 up 1:03, 1 user, load average: 0.07, 0.26, 0.18 192.168.31.114: 11:51:53 up 1:03, 1 user, load average: 0.07, 0.26, 0.18 192.168.31.115: 11:51:53 up 1:03, 1 user, load average: 0.07, 0.26, 0.18 Exception in thread Thread-3: Traceback (most recent call last): File "/Users/icq/.pyenv/versions/2.7.13/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/Users/icq/.pyenv/versions/2.7.13/lib/python2.7/threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "parallel.py", line 12, in ssh key = paramiko.RSAKey.from_private_key_file( pkey_file, password='' ) File "/Users/icq/.pyenv/versions/2.7.13/lib/python2.7/site-packages/paramiko/pkey.py", line 196, in from_private_key_file key = cls(filename=filename, password=password) File "/Users/icq/.pyenv/versions/2.7.13/lib/python2.7/site-packages/paramiko/rsakey.py", line 46, in __init__ self._from_private_key_file(filename, password) File "/Users/icq/.pyenv/versions/2.7.13/lib/python2.7/site-packages/paramiko/rsakey.py", line 174, in _from_private_key_file self._decode_key(data) File "/Users/icq/.pyenv/versions/2.7.13/lib/python2.7/site-packages/paramiko/rsakey.py", line 186, in _decode_key raise SSHException(str(e)) SSHException: Invalid requirement, parse error at "''" 192.168.31.117: 11:51:54 up 1:03, 1 user, load average: 0.07, 0.25, 0.18 192.168.31.115: 11:51:54 up 1:03, 1 user, load average: 0.07, 0.25, 0.18 192.168.31.114: 11:51:54 up 1:03, 1 user, load average: 0.07, 0.25, 0.18 192.168.31.115: 11:51:55 up 1:03, 1 user, load average: 0.07, 0.25, 0.18 192.168.31.116: 11:51:55 up 1:03, 1 user, load average: 0.07, 0.25, 0.18 192.168.31.114: 11:51:55 up 1:03, 1 user, load average: 0.07, 0.25, 0.18 192.168.31.117: 11:51:55 up 1:03, 1 user, load average: 0.07, 0.25, 0.18
相关文章推荐
- 5_paramiko_SSHException Invalid requirement, parse error at
- 使用python的paramiko包的RequirementParseError问题
- python paramiko Error reading SSH protocol banner问题的解决
- org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/atguigu/hi
- 安装paramiko时遇到error in cryptography setup command: Invalid environment marker: python_version < '3'
- 严重: Parse Fatal Error at line 154 column 33: Invalid byte 2 of 2-byte UTF-8 sequence.
- 求助:Parse error in application web.xml file at jndi:/localhost/ssh/WEB-INF/web.xml
- 使用paramiko模块远程连接遇到paramiko.ssh_exception.NoValidConnectionsError的解决办法
- velecity报错:Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error, Encountered: <EOF> after : "\'/order/pay?activity=\" + activityId);\r\n }*/\r\n</script>\r\n#end\r\n" at /a
- error: invalid abbreviation code [25] for DIE at 0x0000003e in Assertion failed: (*offset_ptr == end_prologue_offset), function ParsePrologue, file /S
- 严重: Parse error in application web.xml file at jndi:/localhost/ipws/WEB-INF/web.xml java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml
- 安装paramiko时遇到error in cryptography setup command: Invalid environment marker: python_version < '3'
- org.xml.sax.SAXParseException: Invalid byte 3 of 3-byte UTF-8 sequence
- python下paramiko模块ssh登录
- org.xml.sax.SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence.
- java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException: Invalid encoding name "GB
- Parse Fatal Error at line 1 column 1: Content is not allowed in prolog. org.xml.sax.SAXParseExceptio
- 严重: Parse error in application web.xml file at jndi:/localhost/userLS/WEB-INF/web.xml
- Siebel Exception: SBL-BPR-00162: Error invoking service '%1', method '%2' at step '%3'.
- freemarker.core.InvalidReferenceException: Expression parameters.parseContent is undefined on line 45, column 28 in template/aja