title: Django how to pass basic authorization headers in requests?
body: <p>I'm totally beginner at Django (from a Node/Express background). I need to to make a call to an API that uses basic authorization.</p>
  
  <p>To make requests i'm using the requests module but I don't know where to pass the auth headers. In Axios I normally set the default headers like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>import axios from 'axios'
  const token = `Basic ${Buffer.from(`${process.env.API_USERNAME}:${process.env.API_PASSWORD}`).toString('base64')}`;
  axios.defaults.baseURL = process.env.API_URL;
  axios.defaults.headers.common['Authorization'] = token;
  </code></pre>
  
  <p>My service in Django:</p>
  
  <pre class="lang-py prettyprint-override"><code>from base64 import b64encode
  import requests
  import environ
  environ.Env.read_env()
  
  endpoint = 'some url'
  credentials = f"{env('API_USERNAME')}:{env('API_PASSWORD')}"
  encodedCredentials = str(b64encode(credentials.encode("utf-8")), "utf-8")
  auth = f'"Authorization": "Basic {encodedCredentials}"'
  
  def get_api_data():
      return requests.get(endpoint).json()
  </code></pre>
  
  <p>How should I pass the headers?</p>