#!/usr/bin/python
import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = raw_input('hostname:')
username = raw_input ('username:')
password = getpass.getpass ('password:')
s.login (hostname,username,pawssword)
s.sendline('uptime')
s.prompt()
print s.before
s.sendline('ls-l')
s.prompt()
print s.before
s.sendline('df')
s.prompt()
print s.before
root@kali:/var/myPY# ./ssh.py
File "./ssh.py", line 19
^
SyntaxError: invalid syntax
root@kali:/var/myPY#
我在第19行看不到任何内容,请帮帮我
答案 0 :(得分:0)
try
块后面必须至少有一个except
或finally
。你在这里没有发现任何异常,所以只需摆脱try
部分:
#!/usr/bin/python
import pxssh
import getpass
s = pxssh.pxssh()
hostname = raw_input('hostname:')
username = raw_input ('username:')
password = getpass.getpass ('password:')
s.login (hostname,username,pawssword)
s.sendline('uptime')
s.prompt()
print s.before
s.sendline('ls-l')
s.prompt()
print s.before
s.sendline('df')
s.prompt()
print s.before