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.

Strange exception when call .close()

See original GitHub issue

Hello, folks!

I’m using eznc with SRX240:

from pprint import pprint
from jnpr.junos import Device

dev = Device(host='10.0.x.x', user='view_config', password='xxxxx' )
dev.open()

pprint( dev.facts )

#dev.close()

It works pretty nice with commented out “dev.close”:

{'2RE': False,
 'HOME': '/cf/var/home/view_config',
 'RE0': {'last_reboot_reason': '0x1:power cycle/failure',
         'model': 'RE-SRX240H',
         'status': 'OK',
         'up_time': '4 days, 13 hours, 7 minutes, 50 seconds'},
 'domain': None,
 'fqdn': 'selectel-router',
 'hostname': 'selectel-router',
 'ifd_style': 'CLASSIC',
 'model': 'SRX240H',
 'personality': 'SRX_BRANCH',
 'serialnumber': 'AG3211AA0462',
 'srx_cluster': False,
 'switch_style': 'VLAN',
 'vc_capable': False,
 'version': '12.1X46-D35.1',
 'version_info': junos.version_info(major=(12, 1), type=X, minor=(46, 'D', 35), build=1)}

But when I uncomment dev.close():

from pprint import pprint
from jnpr.junos import Device

dev = Device(host='10.0.6.1', user='view_config', password='DJb2x92VDIpa99ct' )
dev.open()

pprint( dev.facts )
dev.close()

I still get device information but also get exception about permission denied:

python junos_ez.py 
{'2RE': False,
 'HOME': '/cf/var/home/view_config',
 'RE0': {'last_reboot_reason': '0x1:power cycle/failure',
         'model': 'RE-SRX240H',
         'status': 'OK',
         'up_time': '4 days, 13 hours, 10 minutes, 45 seconds'},
 'domain': None,
 'fqdn': 'selectel-router',
 'hostname': 'selectel-router',
 'ifd_style': 'CLASSIC',
 'model': 'SRX240H',
 'personality': 'SRX_BRANCH',
 'serialnumber': 'AG3211AA0462',
 'srx_cluster': False,
 'switch_style': 'VLAN',
 'vc_capable': False,
 'version': '12.1X46-D35.1',
 'version_info': junos.version_info(major=(12, 1), type=X, minor=(46, 'D', 35), build=1)}
Traceback (most recent call last):
  File "junos_ez.py", line 9, in <module>
    dev.close()
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 504, in close
    self._conn.close_session()
  File "/usr/local/lib/python2.7/dist-packages/ncclient/manager.py", line 157, in wrapper
    return self.execute(op_cls, *args, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/ncclient/manager.py", line 227, in execute
    raise_mode=self._raise_mode).request(*args, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/ncclient/operations/session.py", line 28, in request
    return self._request(new_ele("close-session"))
  File "/usr/local/lib/python2.7/dist-packages/ncclient/operations/rpc.py", line 338, in _request
    raise self._reply.error
ncclient.operations.rpc.RPCError: permission denied

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
pavel-odintsovcommented, Dec 17, 2015

Fixed with:

set system login user view_config class read-only
commit
0reactions
tonusoocommented, Aug 3, 2020

Does anyone know which specific command or permission is necessary to add to a class that will allow closing the connection?

.*close-session under allow-commands

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling two different connection closing in a try catch
In my scenario I've two catch and two different closing: close() in the normal case and closeStrange() if a StrangeException is thrown. I...
Read more >
Ensuring file handle is closed in case of an exception [closed]
Your situation. Use closes the resource at the end of the block (lambda). This means that the stream is closed before returning it....
Read more >
Exception Handling in Java - Baeldung
Learn the basics of exception handling in Java as well as some best and worst practices.
Read more >
Getting exception while caling API from httpcleint
Getting exception while caling API from httpcleint. I am writing a windows service which is calling a API after each 60 seconds.
Read more >
How to catch all exceptions in Python - Stackify
close()function ensures that the file is closed even if an exception happens during the program execution. Advantages of Exception Handling and ...
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