cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
971
Views
0
Helpful
16
Replies
Highlighted
Beginner

PYTHONPATH variable

I've installed the python SDK and having troubles running the scripts.

How do I show / set my PYTHONPATH variable?

16 REPLIES 16
Highlighted
Hall of Fame Cisco Employee

Let's assume you have the tutorials installed in /home/cisco/onePK-sdk-1.2.1.194/python/tutorials.  Then run this command:

export PYTHONPATH=/home/cisco/onePK-sdk-1.2.1.194/python/tutorials

Highlighted

Here is the error after setting the PYTHONPATH

Python 2.7.6 (default, Mar 22 2014, 22:59:56)

[GCC 4.8.2] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> print sys.path

['', '/home/andylee/pythonSDK/onePK-sdk-python-rel-1.2.1.194/tutorials', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

>>> exit()

andylee@UbuntoOS:~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/tutorials$ ./BaseTutorial.py -a 10.208.33.101 -R ~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/ca.pem

Traceback (most recent call last):

  File "./BaseTutorial.py", line 23, in <module>

    from onep.element.NetworkApplication import NetworkApplication

  File "/usr/local/lib/python2.7/dist-packages/onep/__init__.py", line 1

SyntaxError: Non-ASCII character '\xf3' in file /usr/local/lib/python2.7/dist-packages/onep/__init__.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

andylee@UbuntoOS:~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/tutorials$

Highlighted
Hall of Fame Cisco Employee

Looks like you might have a corrupt file.  Can you post your /usr/local/lib/python2.7/dist-packages/onep/__init__.py ?

Highlighted

^Có
^TvNSc^@^@^@^@^@^@^@^@^A^@^@^@@^@^@^@s^D^@^@^@d^@^@S(^A^@^@^@N(^@^@^@^@(^@^@^@^@(^@^@^@^@(^@^@^@^@sG^@^@^@/home/andylee/pythonSDK/onePK-sdk-python-rel-1.2.1.194/onep/__init__.pyt^H^@^@^@<module>^A^@^@^@s^@^@^@^@

Highlighted
Hall of Fame Cisco Employee

This file is definitely corrupt.  It should be a 0-byte file.  Delete it, then type:

sudo touch /usr/local/lib/python2.7/dist-packages/onep/__init__.py

Highlighted

In my opinion he pasted "PYC" (binary) file instead "PY".

Highlighted

try this:

export PYTHONPATH=/opt/cisco/onep/python/onePK-sdk-python-YOUR_VERSION/

Highlighted
Hall of Fame Cisco Employee

Yeah, so perhaps something got copied incorrectly.  There really shouldn't be a binary version of that __init__.py, though.

Highlighted

I touched the new __init__.py and now it is a 0 byte file, however, I get the same result:

andylee@UbuntoOS:~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/tutorials$ ./BaseTutorial.py -a 10.208.33.101 -R ~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/ca.pem

Traceback (most recent call last):

  File "./BaseTutorial.py", line 23, in <module>

    from onep.element.NetworkApplication import NetworkApplication

  File "/usr/local/lib/python2.7/dist-packages/onep/element/__init__.py", line 1

SyntaxError: Non-ASCII character '\xf3' in file /usr/local/lib/python2.7/dist-packages/onep/element/__init__.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Highlighted

andylee@UbuntoOS:/usr/local/lib/python2.7/dist-packages/onep$ ls -l __init__.py

-rw-r--r-- 1 root staff 0 Jun 26 11:50 __init__.py

Highlighted
Hall of Fame Cisco Employee

Ah, sorry, I misread the error.  Have a look at /usr/local/lib/python2.7/dist-packages/onep/element/__init__.py.  The contents of this file should be:

from onep.element.NetworkElement import NetworkElement

from onep.element.SessionConfig import SessionConfig

from onep.element.NetworkApplication import NetworkApplication

from onep.element.ApplEvent import ApplEvent

from onep.element.ApplFilter import ApplFilter

from onep.element.ApplListener import ApplListener

from onep.element.CLIEvent import CLIEvent

from onep.element.CLIFilter import CLIFilter

from onep.element.CLIListener import CLIListener

from onep.element.ConnectionEvent import ConnectionEvent

from onep.element.ConnectionListener import ConnectionListener

from onep.element.OIREvent import OIREvent

from onep.element.OIRFilter import OIRFilter

from onep.element.OIRListener import OIRListener

from onep.element.SyslogEvent import SyslogEvent

from onep.element.SyslogFilter import SyslogFilter

from onep.element.SyslogListener import SyslogListener

try:

    from onep.element.ElementConfig import ElementConfig, SyslogHost, DnsServer, TacServer, SnmpServer

except ImportError:

    pass

Highlighted
Hall of Fame Cisco Employee

Hmmm, okay.  It looks like all of your __init__.py files may be in bad shape.  Try deleting /usr/local/lib/python2.7/dist-packages/onep, then reinstall the Python SDK.  These .py files should be readable ASCII text.

Highlighted

I have seen this error pop up in the past.  The Python interpreter seems to be looking for a specific type of encoding and we are using utf-8.  You can correct this at the script level by putting in "# -*- coding: utf-8 -*-" at the top of your script.  Not sure how to correct this system wide other than possible using a PYTHONSTARTUP environment variable pointing to a script that contains that line at the top.

Highlighted

I downloaded the zip again, extracted, deleted the onep directory and reinstalled.

Things are better but still getting an error:

andylee@UbuntoOS:~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/tutorials$ ./BaseTutorial.py -a 10.208.33.101 -R ~/pythonSDK/onePK-sdk-python-rel-1.2.1.194/ca.pem

INFO:onep:BaseTutorial:Reading arguments...

Enter Username : cisco

Enter Password :

INFO:onep:BaseTutorial:Connecting to Network Element...

INFO:onep:BaseTutorial:We have a NetworkElement :

NetworkElement [ 10.208.33.101 ]

WARNING:onep.thrift.transport.CiscoTSSLSocket:Certificate provided neither ip address nor unstructured address

WARNING: Certificate presented by remote host '10.208.33.101' is not verified.

The SHA-1 fingerprint sent by the remote host(10.208.33.101) is:

C1:1D:5E:1D:23:4C:7D:B6:7A:0F:CD:98:3C:6D:67:EE:B7:9D:F8:9C

You MUST verify the certificate on remote host before proceeding!

Choose from following options:

Accept Once (o), Reject (r) (default)

ERROR:onep.element.NetworkElement:IDL Exception: ExceptionIDL(text='User is not authorized to run this application', code=8, context=0)

ERROR:onep.element.NetworkElement:Could not connect to NetworkElement:

ERROR:onep.element.NetworkElement:Thrift exception: TSocket read 0 bytes

Traceback (most recent call last):

  File "./BaseTutorial.py", line 387, in <module>

    tutorial.connect("BaseTutorial")

  File "./BaseTutorial.py", line 106, in connect

    self.session_handle = self.network_element.connect(self.username, self.password, session_config)

  File "/eem-5/shr_scratch/build/nightly/sdk_1.2-nightly/latest/infra/onep/presentation/python/pkg_rel/onep/element/NetworkElement.py", line 1668, in connect

  File "/eem-5/shr_scratch/build/nightly/sdk_1.2-nightly/latest/infra/onep/presentation/python/pkg_rel/onep/element/NetworkElement.py", line 1968, in connect_

onep.core.exception.OnepConnectionException.OnepConnectionException

Content for Community-Ad
Cisco Community October 2020 Spotlight Award Winners
This widget could not be displayed.