title: Python - Basic Authorization (OAuth2.0) to retrieve access token from API
body: <p>I'm trying to generate an access token from an API using the following required information:</p>
  
  <p>Authorization endpoint: <a href="https://api.paylocity.com/IdentityServer/connect/token" rel="nofollow noreferrer">https://api.paylocity.com/IdentityServer/connect/token</a></p>
  
  <p>Authorization Header
  The request is expected to be in the form of a basic authentication request, with the "Authorization" header containing the client-id and client-secret. This means the standard base-64 encoded user:password, prefixed with "Basic" as the value for the Authorization header, where user is the client-id and password is the client-secret.</p>
  
  <p>Content-Type Header
  The "Content-Type" header is required to be "application/x-www-form-urlencoded".</p>
  
  <p>Other Values
  The request must post the following form encoded values within the request body:</p>
  
  <p>grant_type = client_credentials
  scope = WebLinkAPI</p>
  
  <p>I've tried using the Python 'requests' package without success, see below:</p>
  
  <pre><code>import requests
  
  url = "https://api.paylocity.com/IdentityServer/connect/token"
  
  headers = {
      'Authorization': "Basic **********:**********",
      'Content-Type': "application/x-www-form/urlencoded"
      }
  
  body = {
      'grant_type': "client_credentials",
      'scope': 'WebLinkAPI'
  }
  
  response = requests.request("POST", url, headers=headers, params=body)
  
  print(response.text)
  </code></pre>
  
  <p>Instead of an access token, I receive an error message:</p>
  
  <p>{"error":"invalid_client"}</p>
  
  <p>I've verified that my base64 encoded username and password are correct, it looks something like "G/RaNdOm:MoReRaNdOm==" and when I add them to postman it works so my credentials are correct. What could be wrong?</p>