Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.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/5/date/2.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/ssis/2.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 如何使用PyEZ获取Juniper路由器的mac地址表?它在运行时抛出一个错误_Python_Juniper_Junos Automation_Pyez - Fatal编程技术网

Python 如何使用PyEZ获取Juniper路由器的mac地址表?它在运行时抛出一个错误

Python 如何使用PyEZ获取Juniper路由器的mac地址表?它在运行时抛出一个错误,python,juniper,junos-automation,pyez,Python,Juniper,Junos Automation,Pyez,我创建了一个简单的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'

我创建了一个简单的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:~python test1.py 回溯最近一次呼叫上次: 文件test1.py,第11行,在 macs=dev.rpc.get vpls mac tablenormalize=True NameError:未定义名称“vpls”
root@ubuntu:~

JunOS RPC使用下划线转换为Pyez:

将其更改为:


sw=dev.rpc.get_vpls_mac_table

谢谢!它现在使用sw=dev.rpc.get\u vpls\u mac\u表。

Python不允许函数名使用连字符/-。您在哪里找到get-vpls mac table函数的文档/参考资料?仅供参考:您可以将此作为对您有帮助的答案的注释发布,甚至更好。
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()