Token…anyone seen my token

Trying to learn python and scripting has lead me to using API calls. While some things are just fun to play with like FoaaS, others can be really useful.

Generally for a call to work, you need to have an API key. Some places may give you your API key, and some places you may need to generate one.

Generating one wasn’t really the problem, for the most part I was able to use my Google-Fu and find a ton of different ways to do this. Since I’m doing this with Python I decided to use requests for the OAuth2 piece. If you don’t have it already “pip install requests” will grab it for you.

What I was playing with a simple “Hello API” and the examples they had were all using curl.

Step 1 – Get your access token
curl -s -k -H “Content-Type: application/x-www-form-urlencoded” -X POST -d “client_id=” -d “client_secret=” -d “grant_type=client_credentials”

So reading man page/googling the options I was able to find out that “curl -H” is building the header and -d is the payload/data.

The easy part converting the curl to Python:

#! /usr/bin/env python

import requests

payload = {
    'grant_type': 'client_credentials',
    'client_id': "client ID",
    'client_secret': "client secret"
}

headers={
	'content-type': "application/x-www-form-urlencoded"
}

#-----------------------------------------------------------
	#Get access Token

r=requests.post("authentication url", data=payload, headers=headers)
print(r.text)

By doing this, I was able to login and generate the my access token and print it. So now I know what my token is.

Step 2 – Make the call

curl -s -k -H “Accept: application/json” -H “Authorization: Bearer

So I have my token, but how do I use it. Again my example was using curl, and yes it worked…but I wanted to do this as a single script. Google to the rescue!!

Since the response is coming back in json, I should be able to do something with that information, but how? Requests has a built in json decoder. By adding the “r.json()” after the post, I was able to cram the response into an object.

from pprint import pprint

r=requests.post("auth url", data=payload, headers=headers)
d=r.json()

pprint(r.json())

pprint gave me:

{u’access_token’: u’token’,
u’expires_in’: 3599,
u’token_type’: u’Bearer’}

Further digging/swearing/searching/swearing and I figured out how to take that data and make it a variable:

r=requests.post("https://cloudsso.cisco.com/as/token.oauth2", data=payload, headers=headers)
d=r.json()

#pprint(r.json())
mytok=d['access_token']

Now I have my token stored as a usable variable for Step 2. It took me a bit to figure out what the header configuration needed to look like. As you see from the curl example, I needed the Authorization to be + and at first I was trying to push both the “Bearer” and “Token” as a variable, but why? For this usage the token_type will always “Bearer”.

headers={
	'accept': "application/json",
	'authorization': "Bearer " + mytok
}

h=requests.get("hello api url", headers=headers)
print(h.text)

SUCCESS!!! Once I put all the pieces together, I can call the script and it does the login, grabs the token, stores the token as a variable, then uses it for the final call.

#! /usr/bin/env python

import requests
from pprint import pprint

payload = {
    'grant_type': 'client_credentials',
    'client_id': "client ID",
    'client_secret': "client secret"
}

headers={
	'content-type': "application/x-www-form-urlencoded"
}

#-----------------------------------------------------------
	#Get access Token and store in json

r=requests.post("oauth url", data=payload, headers=headers)
d=r.json()

#pprint(r.json())
mytok=d['access_token']

#------------------------------------------------------------
	# Use json data to fill token information
headers={
	'accept': "application/json",
	'authorization': "Bearer " + mytok
}

h=requests.get("hello api url", headers=headers)
print(h.text)

{“response”:”Hello World”}

The Importance of Social Media to the Network Engineer…Or I Tweet therefore I am

It takes a village to raise a child, it takes a Community to raise an engineer.

Over the last few years, more and more of us are using social media. And by “social media” I’m not just talking about email lists, support forums whether vendor supported or not (though they are important as well). No, I’m talking about Twitter, Facebook, Skype, FaceTime and all other forms of instant(ok semi-instant) communication.

This growing trend, from my perspective, has helped us grow more as engineers than anything else I’ve encountered in the 18 or so years I’ve been repairing/installing/designing systems.

In the beginning we all have a mentor. Someone that we are assigned to work with to help get us up to speed. Once you reach a certain level of competence you are thrust out into the big bad network to keep things moving smoothly. Of course you still have your co-workers you can rely on when you need help. But what happens when you encounter a problem they haven’t seen before? You can reach out to the vendors tech support group of course, but sometimes that can take days to get an answer from. I’m not bashing tech support, I spent the better part of five years doing it. But understand that tech support gets tons of calls, and you can only be so productive.

So what do you do? What should you do?

Why, reach out to the social media channels! Tweet out your question or issue! You would be really surprised by who will reply to your issue and how fast a response you can get. I’ve seen engineers in the US work with engineers in the UK, Australia, Germany (you get the picture?) to resolve issues. If someone doesn’t know an answer, they can retweet it to their followers as well:

twitter_help

We have study groups that run across social media, shooting out questions and scenarios they have in their books, and getting responses and explanations from other studiers or people that already have that certification. Being able to reach out to the people that create the materials, like Joe Onisick and Ron Fuller.

From Denise “Fish” Fishburne

In 2001 I tripped into what seemed to be the perfect job for me. I learn, I teach, I help people, and I get to play detective. Had anyone heard of “Denise Fishburne” (aka “Fish”) before 2013? Not really. Did I care? 🙂 Not really. It’s hard to care about not being “known” when you are a lab rat having tons of fun with great co-workers.

Social Media

In 2011 a friend of mine setup introductions with Network World. I submitted 2 sample blog posts and they picked me up. Network World suggested I sign up on this “Twitter” thing. Like many people who aren’t on twitter I had my own notions and ideas of what it was and I hadn’t voluntarily joined it. But I signed up. Didn’t do much with it. Just signed up.

In the spring of 2013 I started playing more with this “twitter thing” prior to CiscoLive. I still remember Jeremy Filliben coming up to me at CiscoLive in 2013 and saying “hi” as if he already knew me. He was my first “in real life” twitter connection.

**January, 2014** – yup… That’s when it all happened. John Spade had asked me on twitter to do a “Cisco Helpout – Women in Network Engineering” podcast. I said yes. Amy Lewis @commsninja was also on the show. Soon after I become a Cisco Champion. Then?

CiscoLive 2014
Met awesome and incredible other Cisco Champions
Hung out at the Social Lounge with the fabulous “tweet-up” gang
Went to my first customer appreciation party ever
Had a lot of fun playing with others with sparkly bats, bacon, tiaras, and masks
Got lots of hugs
After CiscoLive 2014? I have now moved over to writing for PacketPushers and Networking Computing. Admittedly I still pinch myself about Packet Pushers.

I’m your basic lab rat. I like playing in the lab. I come out of the lab about once a year for CiscoLive. Not really the type of job that screams “name recognition OUTSIDE of Cisco comes with this job”. The name recognition outside of Cisco truly has its root in social media. Social media allows me the best of 2 worlds: the lab rat job I love and the interaction outside of Cisco with awesome incredible people I would not have otherwise met.

Dennis Smith
I’d say being active in social & community help me move from Dell to EMC. Never hurts when ppl know who you are before you apply.

Jeremiah Dooley
It’s fair to say that Social and Community have been at the center of every professional opportunity I’ve had since 2010.

I was a Director at a regional service provider in February of 2010 when I initiated the first SP POC for the then new Vblock, long before there were “Acadia” or “VCE” organizations to support it. EMC drove it, with most of the original group of vSpecialists jumping in to assist. Needless to say, there were…issues. I got frustrated, and shared with Chuck Hollis one of the internal e-mails I had sent to my management, and his suggestion was that there were lots of people who would appreciate me sharing my experience publicly. He asked if I’d ever thought of standing up a blog.

From there, things snowballed. My sharing with the community led to relationships, that led to me being hired by Acadia/VCE, that led to me moving into a very visible position with the company. I’ve gotten to travel the world multiple times over, I’ve gotten to work with some of the best and brightest individuals and companies. I’ve been rescued when I needed it, and able to rescue others when they needed it. I’ve found incredible people who I want to learn from, learned to treasure mentoring and helping new people in the community and had fun creating new ways to give back. Being in the right place helps, but it was the community and my willingness to engage them directly that made those things happen. No one is an island in this industry. No one.

The community is the gateway to knowledge. It’s the gateway to resources. It’s the gateway to people and access to technology. Social is how the community interacts. You can’t separate the two, and without them my life would be very different, and my horizons and aspirations would be much smaller.

Heck, I even asked for help writing this blog post!:
twitter