使用Paramiko的connection.send函数的“无效语法”错误

时间:2019-05-23 14:45:56

标签: python ssh

设置代码块以与Checkpoint防火墙交互,尝试运行脚本时出现随机的“无效语法”错误。

如果我在python shell中一个接一个地运行命令,它就可以正常工作。

完整代码位于https://pastebin.com/zKVSXsQs

这是出现错误的代码块:

    connection.send("clish" + "\n")
    time.sleep(1)
    connection.send("delete vpn tunnel" + vpnt + "\n")
    time.sleep(3)
    connection.send("save config" + "\n")
    time.sleep(3)
    #####  This next line is what errors out
    connection.send("add vpn tunnel" + vpnt + "type numbered local 10.50." + subnet ".4 remote 10.50." + subnet + ".1" + "\n")
    ##### End of erring code
    time.sleep(3)
    connection.send("save config" + "\n")
    session.close()
    exit()

这是确切的错误:

connection.send("add vpn tunnel" + vpnt + "type numbered local 10.50." + subnet ".4 remote 10.50." + subnet + ".1" + "\n")

SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:0)

哦,是的:

Traceback (most recent call last):
  File "D:\YES_IT_DOES.py", line 8
    connection.send("add vpn tunnel" + vpnt + "type numbered local 10.50." + subnet ".4 remote 10.50." + subnet + ".1" + "\n")
                                                                                                     ^
SyntaxError: invalid syntax

侧向滚动--->看到插入符号^