Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 运行pwssh时出现无效语法^error_Python_Linux - Fatal编程技术网

Python 运行pwssh时出现无效语法^error

Python 运行pwssh时出现无效语法^error,python,linux,Python,Linux,我在第19行没有看到任何内容,请帮助我Atry块后面必须至少有一个,除了或Afinally。您在这里没有发现任何异常,因此只需去掉try部分: root@kali:/var/myPY# ./ssh.py File "./ssh.py", line 19 ^ SyntaxError: invalid syntax root@kali:/var/myPY# 您有一个try而没有except的try您需要except或最终或else。花点时间检查一下。当解析

我在第19行没有看到任何内容,请帮助我

A
try
块后面必须至少有一个
,除了
或A
finally
。您在这里没有发现任何异常,因此只需去掉
try
部分:

root@kali:/var/myPY# ./ssh.py
File "./ssh.py", line 19

                   ^
SyntaxError: invalid syntax
root@kali:/var/myPY# 

您有一个
try
而没有
except
try
您需要
except
最终
else
。花点时间检查一下。当解析器/编译器在代码结尾后的一行上出现错误时,解析器会期望找到它找不到的东西。在你的情况下,它是一个缺失的“除外”。在其他语言中,您会发现缺少}、)、缺少字符串引号以及其他需要正确关闭的内容也会出现这种情况。还要注意的是,
ls-l
应该是
ls-l
,并且以root用户身份运行脚本几乎不是一个好主意。
root@kali:/var/myPY# ./ssh.py
File "./ssh.py", line 19

                   ^
SyntaxError: invalid syntax
root@kali:/var/myPY# 
#!/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