我已经创建了一个简单的python脚本,以便使用RPC命令从rouer获取vpls mac表。然而,它在运行时抛出错误。有人知道我做错了什么吗?
root@ubuntu:~# cat vpls3.py
#!/usr/bin/python3
from jnpr.junos import Device
from lxml import etree
import jxmlease
username='lab'
password='lab'
dev = Device(host='10.85.164.172', user=username, password=password, normalize=True)
dev.open()
#invoke the RPC command
sw = dev.rpc.get-vpls-mac-table()
print(etree.tostring(sw, encoding='unicode'))root@ubuntu:~#
以下是错误:
root@ubuntu:~# python vpls3.py
Traceback (most recent call last):
File "vpls3.py", line 13, in <module>
sw = dev.rpc.get-vpls-mac-table()
NameError: name 'vpls' is not defined
root@ubuntu:~#我也尝试过下面的脚本:
root@ubuntu:~#猫测试1.py
from jnpr.junos import Device
from lxml import etree
# Set device information with IP-address, login user and passwort
dev = Device( user='lab', host='10.85.164.172', password='lab')
# Connect to the device
dev.open()
# Get MACs
macs = dev.rpc.get-vpls-mac-table(normalize=True)
# Print response of device
print (etree.tostring(macs))
# Close the connection
dev.close()同样的错误:
root@ubuntu:~# python test1.py回溯(最近一次调用):文件"test1.py",第11行,in macs = dev.rpc.get-vpls-mac-table(normalize=True) NameError: name 'vpls‘is not defined root@ubuntu:~#
发布于 2018-12-04 08:15:41
使用下划线将JunOS RPC转换为Pyez:
将其更改为:
sw = dev.rpc.get_vpls_mac_table()
发布于 2018-12-04 08:19:30
谢谢!它现在可以使用sw = dev.rpc.get_vpls_mac_table()。
https://stackoverflow.com/questions/53603742
复制相似问题