1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to APIs in Python

Connected

Exercise

API key authentication with requests

API key-based authentication functions similarly to Basic Authentication, but you must include a unique API key using either a request header or a URL parameter for authenticated requests. Let's explore both approaches.

Good to know:

  1. The requests package has already been imported.
  2. Use the API key/token 8apDFHaNJMxy8Kt818aa6b4a0ed0514b5d3 to authenticate.

Instructions 1/2

undefined XP
  • 1
    • Create a dictionary with a key-value pair for the API key. The API expects the access_token URL parameter to contain your unique API key.
    • Pass the dictionary to the requests.get() function using the correct argument to pass URL parameters.
  • 2
    • Create a dictionary that includes a key-value pair for the API key, this time using the Authorization header.
    • Pass the dictionary to the requests.get() function as headers.