<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cobra SDK fails to import into python script in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4495012#M8</link>
    <description>&lt;P&gt;Very helpful and thank you for the detailed post&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1126943"&gt;@kkhlebop&lt;/a&gt;&amp;nbsp;!!!&amp;nbsp; The only thing I have to add is that I needed to change the url/username/password in the credentials.py script to a different ACI environment.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Oct 2021 14:15:17 GMT</pubDate>
    <dc:creator>Wade Patterson</dc:creator>
    <dc:date>2021-10-29T14:15:17Z</dc:date>
    <item>
      <title>Cobra SDK fails to import into python script</title>
      <link>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4494483#M6</link>
      <description>&lt;P&gt;I'm trying to call modules from the cobra sdk into a python script but it keeps failing to load each time.&amp;nbsp; What I've done:&lt;/P&gt;
&lt;P&gt;- downloaded both .whl files from the APIC (acicobra and acimodel)&lt;/P&gt;
&lt;P&gt;- pip installed both .whl files into a python 3.8 virtual environment&lt;/P&gt;
&lt;P&gt;- performed "run and debug" in VSC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a screenshot of the failure during debug:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1838_898_1.png" style="width: 400px;"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/136025iF3E3FD521252DF1D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1838_898_1.png" alt="1838_898_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that acicobra and acimodel is installed:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cobra installed.JPG" style="width: 400px;"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/136027iD970E47AD6E28F19/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cobra installed.JPG" alt="cobra installed.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not really sure why the script can't find the module.&amp;nbsp; Any help is greatly appreciated!!!! &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 19:26:48 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4494483#M6</guid>
      <dc:creator>Wade Patterson</dc:creator>
      <dc:date>2021-10-28T19:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cobra SDK fails to import into python script</title>
      <link>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4494631#M7</link>
      <description>&lt;P&gt;I don't see the error message in your post, perhaps you are referring to vscode's yellow squiggle underlines that refer to not found modules, so I will investigate that and try to recreate this issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to recreate the issue with python 3.8.3 using these steps. In my case running python from the shell worked (which pointed at my virtual environment). However, when I opened with vscode, I had the same issue as you. This was, I found out, because vscode was trying to use another python environment and not the virtualenv.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My suggestion is to look into how to get vscode to use the virtualenv instead of its default python paths. I might be wrong, but I don't think running &lt;STRONG&gt;source bin/activate&lt;/STRONG&gt; is enough to get the rest of the IDE to use the same python version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the steps I took:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;pyenv local 3.8.3    # switch to python 3.8.3

mkdir apic

cd apic

python -V; pip -V    # to confirm I am using correct version of python 3.8.3

python -m venv venv

source venv/bin/activate

python -V; pip -V    # to confirm that I am using the python 3.8.3 from the virtualenv

cp Downloads/aci* .    # copy the apic sdk files to local dir (i got these from https://developer.cisco.com/docs/aci/#!cobra-sdk-downloads/aci-learning-labs )

pip install acicobra-4.2_3h-py2.py3-none-any.whl    # install acicobra

pip install acimodel-4.2_3h-py2.py3-none-any.whl    # install acimodel

git clone https://github.com/CiscoDevNet/aci-learning-labs-code-samples

cd aci-learning-labs-code-samples/apic_fabric_setup    # go to the directory where startup file is at

code . # open vscode. then I saw the same marks - also trying to run the code from vscode fails at the import

python startup_script.py  # this code gets past the imports and fails at connection as I didn't edit my code's connection parms

### output: ###

❯ python startup_script.py
Baselining APIC Simulator for Learning Labs
Setting up Fabric Nodes
Traceback (most recent call last):
  File "startup_script.py", line 30, in &amp;lt;module&amp;gt;
    md.login()
  File "/Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages/cobra/mit/access.py", line 32, in login
    self._accessImpl.login()
  File "/Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages/cobra/internal/rest/accessimpl.py", line 128, in login
    loginHandler.login(self._session)
  File "/Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages/cobra/internal/rest/accessimpl.py", line 81, in login
    session._parseResponse(rsp)
  File "/Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages/cobra/mit/session.py", line 179, in _parseResponse
    rsp.raise_for_status()
  File "/Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://sandboxapicdc.cisco.com/api/aaaLogin.json
&lt;/PRE&gt;
&lt;P&gt;Here are my pip shows:&lt;/P&gt;
&lt;PRE&gt;❯ pip show acimodel
Name: acimodel
Version: 4.2-3h
Summary: The Management Information Tree
Home-page: UNKNOWN
Author: Cisco Systems
Author-email: mtimm@cisco.com
License: Cisco Systems Inc. (Copyright 2014)
Location: /Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages
Requires: acicobra
Required-by:

❯ pip show acicobra
Name: acicobra
Version: 4.2-3h
Summary: Access API for the Management Information Tree
Home-page: UNKNOWN
Author: Cisco Systems
Author-email: gurssing@cisco.com
License: Cisco Systems Inc. (Copyright 2013 - 2014)
Location: /Users/kkhlebop/Dropbox/src/apic/venv/lib/python3.8/site-packages
Requires: future, ply, requests, setuptools
Required-by: acimodel&lt;/PRE&gt;
&lt;P&gt;Below is a screenshot showing the python paths and pip show for both modules - as you can see its pointing at wrong path and can't find it. If I do the source bin/activate, it will work for the terminal, but the rest of the IDE will not follow with - however I know there is a way, just need to look for vscode documentation or forums on how to get VSCODE working with virtualenv.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screen Shot 2021-10-28 at 7.27.26 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/136042iC78E60E4792B15AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2021-10-28 at 7.27.26 PM.png" alt="Screen Shot 2021-10-28 at 7.27.26 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditor_8a449aa33eb0a6kkhlebop_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditor_8a449aa33eb0a6kkhlebop_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 02:36:02 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4494631#M7</guid>
      <dc:creator>kkhlebop</dc:creator>
      <dc:date>2021-10-29T02:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Cobra SDK fails to import into python script</title>
      <link>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4495012#M8</link>
      <description>&lt;P&gt;Very helpful and thank you for the detailed post&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1126943"&gt;@kkhlebop&lt;/a&gt;&amp;nbsp;!!!&amp;nbsp; The only thing I have to add is that I needed to change the url/username/password in the credentials.py script to a different ACI environment.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 14:15:17 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/cobra-sdk-fails-to-import-into-python-script/m-p/4495012#M8</guid>
      <dc:creator>Wade Patterson</dc:creator>
      <dc:date>2021-10-29T14:15:17Z</dc:date>
    </item>
  </channel>
</rss>

