Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using the Requests Library

Jay Norris
Jay Norris
14,824 Points

username and password referenced in GET url?

In the workshop, you're requesting data from httpbin and the username and password are also stored at httpbin? I don't understand that part of it.

What if you were requesting data from httpbin, but the username and password weren't also stored there?

I just finished Django Rest Framework course too. (Great course!) I need to GET information from an API using digest auth for my Django project. I'm provided an "api key" and "secret key", but I still don't understand where/how to store and reference them when calling the API.

Kenneth Love

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

With httpbin, whatever username and password you send in the URL is the one it auths you against.

They gave you keys for digest auth? That sounds more like OAuth.

Jay Norris
Jay Norris
14,824 Points

Much appreciated! Last question, I promise. They confirm it's digest and even provided a python example. I'm still confused after researching it though. The requests library probably makes that simpler, but do I need to create a file on my site to store that data to respond with?

The api returns the price of Rx medications. Here is what they say:

"It’s definitely just a digest, not OAuth – here’s a quick example using python":

querystring = Lipitor&api_key=MY_API_KEY signature = hmac.new(secret_key, msg=querystring, digestmod=hashlib.sha256).digest() signature = base64.b64encode(signature, “__”) ?name=Lipitor&api_key=MY_API_KEY&sig=gn9UAFOfMaEOMEmzH0hpk7k_QnRe1inD_=