title: Python API KeyError
body: <p>I'm new to both python and APIs. lol. But google isn't helping. I have the below simple authentication request and am getting a <code>KeyError: 'token' </code> from the line, <code>authorization = {&quot;Authorization&quot;: &quot;Bearer &quot; + token['token']}</code></p>
  <p>I appreciate any guidance you can provide!</p>
  <pre><code>#!/usr/bin/python3
  
  import requests
  import argparse
  import math
  import os
  import json
  
  
  export_format_map = {
      &quot;csv&quot;: &quot;zip&quot;,
      &quot;json&quot;: &quot;json&quot;,
      &quot;kml&quot;: &quot;kml&quot;
      }
  
  def download_logs(args):
      &quot;&quot;&quot;
      NOTE: Requires user credentials
      Downloads log files from user-specified host in user-specified file format.
      &quot;&quot;&quot;
      rest_api = &quot;https://address.here/api/1.0&quot;
      
      # Step 1. Login and get token to authenticate requests
      print(f&quot;Logging into {rest_api}...&quot;)
      
      # Get username and password from environment variables
      username = os.environ.get('USERNAME')
      password = os.environ.get('PASSWORD')
      
      # Put the credentials into a dictionary object
      credentials = {&quot;email&quot;: username, &quot;password&quot;: password}
  
      r = requests.post(f&quot;{rest_api}/authentication/login&quot;, json=credentials)
      
      # Build the JWT compliant authorization dictionary
      token = json.loads(r.text)
      authorization = {&quot;Authorization&quot;: &quot;Bearer &quot; + token['token']}
  
   # Step 2. Gather a list of contacts filtered to be within the min/max timestamps
      def get_agents(params):
          &quot;&quot;&quot;Sends GET request to API with provided parameters; Returns response.&quot;&quot;&quot;
          response = requests.get(
              url=f&quot;{rest_api}/agent&quot;,
              params=params,
              headers=authorization
          ).json()
          return response
     #code continues.....
  
  </code></pre>
  <p>I have also tried setting up the token request like this with the same error:</p>
  <pre><code>TOKEN = requests.post(
          url=f&quot;{rest_api}/authentication/login&quot;,
          data={
              &quot;email&quot;: input(&quot;\nusername/email: &quot;),
              &quot;password&quot;: getpass.getpass(),
          }
      ).json()
  
  authorization = {&quot;Authorization&quot;: &quot;Bearer &quot; + TOKEN['token']}
  </code></pre>