question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IO Exception Over Serial On Windows

See original GitHub issue

I cannot get PyEZ to connect to my juniper switch on Windows using the serial port. For my application I cannot use SSH/telnet and I need it to work over the serial port.

On login I get an error in tty_netconf._receive() with the usage of select.

According to the official python docs the select operation is not supported on Windows for file objects (https://docs.python.org/3/library/select.html?highlight=select#select.select).

Is there something else than the select than can be used to wait on the IO under Windows ?

Thanks

Here is the command and the output with the error.

Using Windows 10 1809 Python 3.6.8 junos-eznc 2.2.1

To Replicate

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

logging.basicConfig(level=logging.DEBUG)

dev = Device(mode='serial', port='COM4', user='root', passwd=None)
dev.open()

Output

INFO:jnpr.junos.tty:TTY: connecting to TTY:COM4 ...
INFO:jnpr.junos.tty:TTY: OK.....starting NETCONF
WRITExml-mode netconf need-trailer
ERROR:jnpr.junos.console:Exception occurred: login:fileno

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\jnpr\junos\console.py", line 221, in open
    raise ex
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\jnpr\junos\console.py", line 211, in open
    self._tty_login()
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\jnpr\junos\console.py", line 316, in _tty_login
    self._tty.login()
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\jnpr\junos\transport\tty.py", line 115, in login
    self.nc.open(at_shell=self.at_shell)
  File "C:\Users\uesr\AppData\Local\Programs\Python\Python36\lib\site-packages\jnpr\junos\transport\tty_netconf.py", line 68, in open
    self.hello = self._receive()
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\jnpr\junos\transport\tty_netconf.py", line 142, in _receive
    raise err
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
moophatcommented, Mar 23, 2020

console.log

@moophat How about going from 1 to 2. If 1 doesn’t work, I can work with remote access.

Hi @vnitinv , apolozies for the late reply, there was an power issue with our lab so I have to turn off some device during the weekends.

But good new is that the updated code seem to work, even when the console session was currently in a logged in prompt, which is great. I’ll need to test further functionality with the tableview retrieval and setting new configuration before confirming that everything work as expected. But for now thank you for the update

Attached is the log file (logging output is wrapped in my own custom log format handler ), the only time it produce an error is when another process has already occupied the COM port - which is totally expected and should not be considered a code error.

0reactions
shivintwrkcommented, Mar 19, 2020

@vnitinv : I have tried with the context manager but it gives me the the same “io.UnsupportedOperation: fileno” exception. I used --upgrade this time to install the package hoping that it would resolve the issue of not picking up latest code. It did uninstall and reinstall the package.

Successfully built junos-eznc
Installing collected packages: junos-eznc
  Attempting uninstall: junos-eznc
    Found existing installation: junos-eznc 2.3.2.dev0
    Uninstalling junos-eznc-2.3.2.dev0:
      Successfully uninstalled junos-eznc-2.3.2.dev0
Successfully installed junos-eznc-2.3.2.dev0

I tried with context manager this time and got a different exception (the lib looks the same though):

INFO:jnpr.junos.tty:TTY: connecting to TTY:COM4 ...
INFO:jnpr.junos.tty:TTY: logging in......
WARNING:jnpr.junos.tty:login_warn: waiting on TTY.....
INFO:jnpr.junos.tty:TTY: OK.....starting NETCONF
DEBUG:jnpr.junos.tty_netconf:Received:
b''
INFO:jnpr.junos.console:facts: retrieving device facts...
INFO:jnpr.junos.tty_netconf:Calling rpc: b'<rpc><load-configuration format="text" action="set"><configuration-set>set system host-name test</configuration-set></load-configuration></rpc>'
DEBUG:jnpr.junos.tty_netconf:Received:
b''
C:\Python37\lib\site-packages\jnpr\junos\device.py:825: RuntimeWarning: An unknown exception occured - please report.
  RuntimeWarning)
INFO:jnpr.junos.tty:logout: logging out.....
INFO:jnpr.junos.tty_netconf:Calling rpc: b'<rpc><close-session/></rpc>'
DEBUG:jnpr.junos.tty_netconf:Received:
b''
Traceback (most recent call last):
  File "c:/Users/###", line 208, in <module>
    main()
  File "c:/Users/###", line 181, in main
    cu.load('set system host-name test', format='set', ignore_warning=True)
  File "C:\Python37\lib\site-packages\jnpr\junos\utils\config.py", line 539, in load
    ignore_warning=ignore_warning)
  File "C:\Python37\lib\site-packages\jnpr\junos\utils\config.py", line 456, in try_load
    **rpc_xattrs)
  File "C:\Python37\lib\site-packages\jnpr\junos\rpcmeta.py", line 277, in load_config
    return self._junos.execute(rpc, ignore_warning=ignore_warning)
  File "C:\Python37\lib\site-packages\jnpr\junos\decorators.py", line 76, in wrapper
    return function(*args, **kwargs)
  File "C:\Python37\lib\site-packages\jnpr\junos\decorators.py", line 31, in wrapper
    return function(*args, **kwargs)
  File "C:\Python37\lib\site-packages\jnpr\junos\device.py", line 801, in execute
    'filter_xml'))
  File "C:\Python37\lib\site-packages\jnpr\junos\decorators.py", line 116, in wrapper
    rsp = function(self, *args, **kwargs)
  File "C:\Python37\lib\site-packages\jnpr\junos\console.py", line 280, in _rpc_reply
    self._huge_tree
  File "C:\Python37\lib\site-packages\ncclient\xml_.py", line 174, in __init__
    self.__doc = self.remove_namespaces(self.__result)
  File "C:\Python37\lib\site-packages\ncclient\xml_.py", line 222, in remove_namespaces
    parser=self.__parser))),
  File "src\lxml\etree.pyx", line 3435, in lxml.etree.parse
  File "src\lxml\parser.pxi", line 1857, in lxml.etree._parseDocument
  File "src\lxml\parser.pxi", line 1877, in lxml.etree._parseMemoryDocument
  File "src\lxml\parser.pxi", line 1758, in lxml.etree._parseDoc
  File "src\lxml\parser.pxi", line 1068, in lxml.etree._BaseParser._parseUnicodeDoc
  File "src\lxml\parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
  File "src\lxml\parser.pxi", line 711, in lxml.etree._handleParseResult
  File "src\lxml\parser.pxi", line 640, in lxml.etree._raiseParseError
  File "<string>", line 1
lxml.etree.XMLSyntaxError: Specification mandates value for attribute error-in-receive, line 1, column 27
Read more comments on GitHub >

github_iconTop Results From Across the Web

IOException error in opening a virtual serial port with Powershell
Hello,. I have installed a plug-and-play measurement instrument, with a USB terminal, and it appears as a serial COM port.
Read more >
SerialPort.Open() --IOException -- "The parameter is incorrect."
I have written the following code to configure the serial port when the MainForm loads. On first run it gives IOException when port...
Read more >
serial port: I/O error - Google Groups
What could be the cause of an I/O error on an serial port? I know this is somewhat generic, but... tclkit 8.5.8 on...
Read more >
Overview of Serial Port I/O Routines (Windows*)
The serial port I/O (SPORT_ xxx ) routines help you perform basic input and output to serial ports. These routines are available only...
Read more >
pySerial API
SerialException – In case the device can not be found or can not be ... For possible values refer to the list for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found