Guest User

Untitled

a guest
Mar 21st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. $ cat CiscoNet_6.py
  2. #!/usr/bin/python3
  3. from __future__ import absolute_import, division, print_function
  4. import netmiko
  5. import paramiko
  6. import json
  7. ######################################
  8. ## JSON: Javascript object Notation ##
  9. ######################################
  10. # creating a tuple
  11. netmiko_exceptions = (netmiko.ssh_exception.NetMikoAuthenticationException,
  12. netmiko.ssh_exception.NetMikoTimeoutException)
  13.  
  14. with open('devices.json') as dev_file:
  15. devices = json.load(dev_file)
  16.  
  17. for device in devices:
  18. try:
  19. print('-'*79)
  20. print('Net Device Address Is: -->', device['ip'])
  21. #print('Net Device Address Is: -->', device)
  22. connection = netmiko.ConnectHandler(**device)
  23. print(connection.send_command('show clock'))
  24. print('-'*79)
  25. connection.disconnect()
  26. except netmiko_exceptions as e:
  27. #print('Authentication failed to', 'Device')
  28. print('Failed to', device['ip'], e)
  29. #print('Failed to', device, e)
  30.  
  31. [
  32. {
  33. ip: "192.168.0.200",
  34. device_type: "cisco_ios",
  35. username: "nettest",
  36. password: "cisco123",
  37. }
  38. ]
  39.  
  40. Traceback (most recent call last):
  41. File "./CiscoNet_6.py", line 18, in <module>
  42. devices = json.load(dev_file)
  43. File "/python/v3.6.1/lib/python3.6/json/__init__.py", line 299, in load
  44. parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  45. File "/python/v3.6.1/lib/python3.6/json/__init__.py", line 354, in loads
  46. return _default_decoder.decode(s)
  47. File "/python/v3.6.1/lib/python3.6/json/decoder.py", line 339, in decode
  48. obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  49. File "/python/v3.6.1/lib/python3.6/json/decoder.py", line 355, in raw_decode
  50. obj, end = self.scan_once(s, idx)
  51. json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 3 (char 7)
Add Comment
Please, Sign In to add comment