Python中文
首页
教程
问答
标签
搜索
登录
注册
来自ncclient导入管理器;无法调用close_会话()
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试执行以下代码,但在“close_session()”函数中出现了这些错误。如何修复它?我是python新手</p> <p>我正在学习netconf,并尝试使用python netconf配置路由器。我已经导入了库,似乎我做的每件事都是正确的</p> <pre><code>from ncclient import manager from pprint import pprint import xmltodict import xml.dom.minidom from router_info import router print(router["host"]) print(router["port"]) print(router["username"]) print(router["password"]) netconf_filter = open("/Users/ljames/netconf/netconf-filter.xsd").read() with manager.connect(host=router["host"], port=router["port"], username=router["username"], password=router["password"], hostkey_verify=False) as m: interface_netconf = m.get(netconf_filter) # xmlDom = xml.dom.minidom.parseString(str(interface_netconf)) # print(xmlDom.toprettyxml(indent='')) # print('*' * 25 + 'Break' + '*' * 25) interface_python = xmltodict.parse(interface_netconf.xml)["rpc-reply"]["data"] # pprint(interface_python) name = interface_python['interfaces']['interface']['name']['#text'] print(name) config = interface_python["interfaces"]["interface"] op_state = interface_python["interfaces-state"]["interface"] print("Start") print(f"Name: {config['name']['#text']}") print(f"Description: {config['description']}") print(f"packets In {op_state['statistics']['in-unicast-pkts']}") m.close_session() </code></pre> <p>以下是错误消息:</p> <pre><code>mac@user % /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 /Users/ljames/netconf/netconf-5.py ios-xe-mgmt-latest.cisco.com 10000 developer C1sco12345 GigabitEthernet2 Start Name: GigabitEthernet2 Description: YJ-interface packets In 146 Traceback (most recent call last): File "/Users/ljames/netconf/netconf-5.py", line 36, in <module> m.close_session() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/manager.py", line 231, in execute return cls(self._session, File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/operations/session.py", line 28, in request return self._request(new_ele("close-session")) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/operations/rpc.py", line 327, in _request self._session.send(req) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/transport/session.py", line 167, in send raise TransportError('Not connected to NETCONF server') ncclient.transport.errors.TransportError: Not connected to NETCONF server </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我有完全相同的问题,这是我的结论:</p> <p>问题可能是在<code>with</code>块之外使用<code>m.close_session()</code>。事实上,您不应该在<code>with</code>块中使用<code>close_session</code>,因为清理是自动执行的。只要逐行调试,就可以看到当退出<code>with</code>块时,<code>m.connected</code>被设置为false</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中两个字典的交集
9 回答
python中两个字符串上的异或操作数?
6 回答
Python中两个字符串中的类似句子
9 回答
Python中两个字符串之间的Hamming距离
1 回答
python中两个字符串之间的匹配模式
2 回答
python中两个字符串之间的按位或
9 回答
python中两个字符串之间的数据(字节)切片
3 回答
python中两个字符串之间的模式
4 回答
python中两个字符串作为子字符串的区别
7 回答
Python中两个字符串元组的比较
3 回答
Python中两个字符串列表中的公共字符串
8 回答
python中两个字符串的Anagram测试
3 回答
Python中两个字符串的正则匹配
7 回答
python中两个字符串的笛卡尔乘积
9 回答
Python中两个字符串相似性的比较
2 回答
python中两个字符串语义相似度的求法
5 回答
Python中两个字符置换成固定长度的字符串,每个字符的数目相等
7 回答
Python中两个对数方程之间的插值和平滑数据
6 回答
Python中两个对象之间的And/Or运算符
6 回答
python中两个嵌套字典中相似键的和值
10 回答