cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
9217
Views
5
Helpful
11
Replies

How can I make this script to run?

Hello I've recently started to learn about devnet so I'm starting with easy things like how to code or how to manage Cisco DNA Center but I've got a difficult start when I'm trying to compile this script I always get the message of WARNING dnac_config is not a module I know it's a python file but I don't know how to make it work 

 

Just in case I'm going to share the code:

 

import requests   # We use Python external "requests" module to do HTTP query
import dnac_config # DNA-C IP is assigned in dnac_config.py
from requests.auth import HTTPBasicAuth


def get_auth_token():
"""
Building out Auth request. Using requests.post to make a call to the Auth Endpoint
"""
url = 'https://sandboxdnac.cisco.com/dna/system/api/v1/auth/token' # Endpoint URL
resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) # Make the POST Request
token = resp.json()['Token'] # Retrieve the Token from the returned JSON
print("Token Retrieved: {}".format(token)) # Print out the Token
return token # Create a return statement to send the token back for later use

if __name__ == "__main__":
get_auth_token()

I've been using PyCharm for easy examples about Postman but where I'm starting to begin my journey it's almost impossible (Also I don't know how to use Cisco DNA Center). I will be so grateful if you answer me correctly to get an output about all of this.

 

Greetings,

A newbie