2

我一直在尝试使用 JunOS pyEZ 来配置需要串行连接进行初始配置的 SRX。使用下面提到的代码会引发 I/O 异常:

from jnpr.junos import Device
from jnpr.junos.utils.config import Config
import logging

......
logging.basicConfig(level=logging.INFO)
dev = Device(user='root', passwd='*****', mode='serial', port='COM4', gather_facts=True)
print(dev.facts)
cu = Config(dev)
cu.load('set system host-name test', format='set', ignore_warning=True)
cu.commit()
.....

例外:

INFO:jnpr.junos.tty:TTY: connecting to TTY:COM4 ...
INFO:jnpr.junos.tty:TTY: logging in......
INFO:jnpr.junos.tty:TTY: OK.....starting NETCONF
ERROR:jnpr.junos.console:Exception occurred: login:fileno

Traceback (most recent call last):
File "c:/Users/################", line 208, in
main()
File "c:/Users/################", line 178, in main
with Device(user='root', passwd='*******', mode='serial', port='COM4', gather_facts=True, console_has_banner=True) as dev:
File "C:\Python37\lib\site-packages\jnpr\junos\console.py", line 336, in enter
self._conn = self.open()
File "C:\Python37\lib\site-packages\jnpr\junos\console.py", line 222, in open
raise ex
File "C:\Python37\lib\site-packages\jnpr\junos\console.py", line 212, in open
self._tty_login()
File "C:\Python37\lib\site-packages\jnpr\junos\console.py", line 319, in _tty_login
self._tty.login()
File "C:\Python37\lib\site-packages\jnpr\junos\transport\tty.py", line 116, in login
self.nc.open(at_shell=self.at_shell)
File "C:\Python37\lib\site-packages\jnpr\junos\transport\tty_netconf.py", line 68, in open
self.hello = self._receive()
File "C:\Python37\lib\site-packages\jnpr\junos\transport\tty_netconf.py", line 142, in _receive
raise err
File "C:\Python37\lib\site-packages\jnpr\junos\transport\tty_netconf.py", line 140, in _receive
rd, wt, err = select.select([self._tty._rx], [], [], 0.1)
io.UnsupportedOperation: fileno

将 open() 与上述代码一起使用会产生相同的错误。使用 SSH 连接运行类似的代码可以正常工作。在 WSL 中运行它会产生相同的错误。PS:使用 Python3.7 在 Windows 10 上运行

4

0 回答 0