pycsco icon indicating copy to clipboard operation
pycsco copied to clipboard

NameError: global name 'NXAPI' is not define

Open rdrash opened this issue 9 years ago • 6 comments

When I try to run the example script I get the following error. File "C:\Python27\lib\site-packages\pycsco-0.3.0-py2.7.egg\pycsco\nxos\device.py", line 61, in init self.sw1 = NXAPI NameError: global name 'NXAPI' is not defined

I've tried a couple of fixes, but not being a python expert I'm stuck.

rdrash avatar Nov 04 '15 20:11 rdrash

Can you paste what you are trying too including import statements, etc. ?

On Nov 4, 2015, at 3:13 PM, rdrash [email protected] wrote:

When I try to run the example script I get the following error. File "C:\Python27\lib\site-packages\pycsco-0.3.0-py2.7.egg\pycsco\nxos\device.py", line 61, in init self.sw1 = NXAPI NameError: global name 'NXAPI' is not defined

I've tried a couple of fixes, but not being a python expert I'm stuck.

— Reply to this email directly or view it on GitHub.

jedelman8 avatar Nov 04 '15 20:11 jedelman8

Here is the script I'm trying to run. import xmltodict import json from pycsco.nxos.device import Device from pycsco.nxos.utils.nxapi_lib import get_list_of_vlans

switch = Device(ip='rdc-mdf-rsw21',username='##############',password='####################')

get_sh_ver = switch.show('show version')

sh_ver_dict = xmltodict.parse(get_sh_ver[1])

print json.dumps(sh_ver_dict, indent=4)

rdrash avatar Nov 04 '15 20:11 rdrash

Can you please post everything with the error so I can see the full workflow? So, please post the exact code you are using along with the error. How did you install pycsco? What OS are you using?

On Nov 4, 2015, at 3:38 PM, rdrash [email protected] wrote:

Here is the script I'm trying to run. import xmltodict import json from pycsco.nxos.device import Device from pycsco.nxos.utils.nxapi_lib import get_list_of_vlans

switch = Device(ip='rdc-mdf-rsw21',username='##############',password='####################')

get_sh_ver = switch.show('show version')

this returns a tuple of 2 xml objects. the first is headers, etc. and the second is the data we want

sh_ver_dict = xmltodict.parse(get_sh_ver[1])

converting the second element to a python dictionary

print json.dumps(sh_ver_dict, indent=4)

— Reply to this email directly or view it on GitHub.

jedelman8 avatar Nov 05 '15 01:11 jedelman8

I'm running win7. I used easy_install do to my companies firewall policy. Here is the full script and the output. username and password has been altered for obvious reasons. author = 'aaaaaaa'

import xmltodict import json from pycsco.nxos.device import Device switch = Device(ip='rdc-mdf-rsw21',username='aaaaaaaaa',password='aaaaaaaa') get_sh_ver = switch.show('show version') sh_ver_dict = xmltodict.parse(get_sh_ver[1]) print json.dumps(sh_ver_dict, indent=4)


No module named yaml


Traceback (most recent call last): File "C:\Users\japon\PycharmProjects\nxapi\test.py", line 6, in switch = Device(ip='rdc-mdf-rsw21',username='aaaaaaaaa',password='aaaaaaaa') File "C:\Python27\lib\site-packages\pycsco-0.3.0-py2.7.egg\pycsco\nxos\device.py", line 61, in init self.sw1 = NXAPI() NameError: global name 'NXAPI' is not defined

rdrash avatar Nov 05 '15 14:11 rdrash

So, you should install this via pip or clone the repo and install from source (on linux it's sudo python setup.py install). Don't use easy_install. We've never installed pycsco via easy_install (not sure it should work to be honest). Have also not tested on windows, but that should not be a problem.

jedelman8 avatar Nov 05 '15 16:11 jedelman8

I get the same error but I think I narrowed it down to the yaml library not being installed. If I install PyYAML it works fine but if I uninstall it I get:

======================================================================
ERROR: test suite for <class 'TestNXOSDriver.TestGetterNXOSDriver'>
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/nose/suite.py", line 209, in run
    self.setUp()
  File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/nose/suite.py", line 292, in setUp
    self.setupContext(ancestor)
  File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/nose/suite.py", line 315, in setupContext
    try_run(context, names)
  File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/nose/util.py", line 471, in try_run
    return func()
  File "/Users/dbarroso/workspace/napalm-nxos/test/unit/TestNXOSDriver.py", line 47, in setUpClass
    cls.device = NXOSDriver(hostname, username, password, timeout=60)
  File "/Users/dbarroso/workspace/napalm-nxos/napalm_nxos/nxos.py", line 55, in __init__
    timeout=timeout)
  File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/pycsco/nxos/device.py", line 66, in __init__
    self.sw1 = NXAPI()
NameError: global name 'NXAPI' is not defined
-------------------- >> begin captured stdout << ---------------------
***************************
No module named yaml
***************************

--------------------- >> end captured stdout << ----------------------

dbarrosop avatar Mar 16 '16 10:03 dbarrosop