2

程序:

from netmiko import ConnectHandler

iosv_l2 = {
    'device_type': 'cisco_ios',
    'ip':   '192.168.122.50',
    'username': 'sagar',
    'password': 'sagar',

}

net_connect =ConnectHandler(**iosv_l2)
output =net_connect.send_command('show ip int brief')
print(output)

config_commands = [ 'int loop 0', 'ip addre 1.1.1.1 255.255.255.0']
output = net_connect.send_config_set(config_commands)
print (output)

错误:

Traceback (most recent call last):
  File "netmiko1", line 3, in <module>
    from netmiko import ConnectHandler
  File "/usr/local/lib/python2.7/dist-packages/netmiko/__init__.py", line 7, in <module>
    from netmiko.ssh_dispatcher import ConnectHandler
  File "/usr/local/lib/python2.7/dist-packages/netmiko/ssh_dispatcher.py", line 2, in <module>
    from netmiko.a10 import A10SSH
  File "/usr/local/lib/python2.7/dist-packages/netmiko/a10/__init__.py", line 1, in <module>
    from netmiko.a10.a10_ssh import A10SSH
  File "/usr/local/lib/python2.7/dist-packages/netmiko/a10/a10_ssh.py", line 3, in <module>
    from netmiko.cisco_base_connection import CiscoSSHConnection
  File "/usr/local/lib/python2.7/dist-packages/netmiko/cisco_base_connection.py", line 143
    msg = f"Login failed: {self.host}"
                                     ^
SyntaxError: invalid syntax
4

2 回答 2

1

是的,Netmiko 3.xx 需要 Python 3.6+,因此您需要将 Python 版本升级到该版本(或降级到 Netmiko 2.4.2)。

于 2020-02-09T00:20:32.530 回答
0

该模块使用f-strings,仅在 3.6 版中添加到 Python 中。要解决此问题,请将 Python 升级到 3.6 或更高版本。您当前使用的是 2.7。

Netmiko的3.0.0 更新删除了对 Python 2.7 的所有支持。为了继续使用 Python 2.7,您必须降级到版本 2.4.2。

于 2020-01-22T14:39:08.500 回答