运行pwssh时语法无效^错误

时间:2014-07-29 08:56:58

标签: python linux

#!/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行看不到任何内容,请帮帮我

1 个答案:

答案 0 :(得分:0)

try块后面必须至少有一个exceptfinally。你在这里没有发现任何异常,所以只需摆脱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