Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: global name 'NXAPI' is not define #14

Open
rdrash opened this issue Nov 4, 2015 · 6 comments
Open

NameError: global name 'NXAPI' is not define #14

rdrash opened this issue Nov 4, 2015 · 6 comments

Comments

@rdrash
Copy link

rdrash commented Nov 4, 2015

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.

@jedelman8
Copy link
Owner

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

On Nov 4, 2015, at 3:13 PM, rdrash notifications@github.com 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.

@rdrash
Copy link
Author

rdrash commented Nov 4, 2015

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)

@jedelman8
Copy link
Owner

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 notifications@github.com 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.

@rdrash
Copy link
Author

rdrash commented Nov 5, 2015

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

@jedelman8
Copy link
Owner

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.

@dbarrosop
Copy link

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 << ----------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants