title: Cannot POST request using service account key file in Python, getting 'Invalid IAP credentials: Unable to parse JWT', '401 Status Code'
body: <p>I am trying to send a POST request to a Google App Engine service with a JSON body accompanied by an authorization token. I am generating the access token from a local service account key JSON file. The code below is generating a credential but finally the authorization is being rejected. I also tried different ways already. Even tried writing the request in Postman with a Bearer token in the Header, or even as a plain cURL command. But whatever I try, getting a 401 authentication error. I need to make sure whether the problem is in my side or on the other side with the service. Explored every documentation avaliable but no luck.</p>
  <pre><code>from google.auth.transport import requests
  from google.oauth2 import service_account
  from google.auth.transport.requests import AuthorizedSession
  
  CREDENTIAL_SCOPES = [&quot;https://www.googleapis.com/auth/cloud-platform&quot;]
  CREDENTIALS_KEY_PATH = 'my-local-service-account-key-file.json'
  
  #the example service url I am trying to hit with requests
  url = 'https://test.appspot.com/submit'
  
  headers = {&quot;Content-Type&quot;: &quot;application/json&quot;}
  
  #example data I am sending with the request body
  payload = {
    &quot;key1&quot;: &quot;value 1&quot;,
    &quot;key2&quot;: &quot;value 2&quot;
  }
  
  
  credentials = service_account.Credentials.from_service_account_file(
                      CREDENTIALS_KEY_PATH,
                      scopes=CREDENTIAL_SCOPES
                      )
  
  credentials.refresh(requests.Request())
  
  authed_session = AuthorizedSession(credentials)
  
  response = authed_session.request('POST',
                                    url,
                                    headers=headers,
                                    data=payload
                                  )
  
  #adding some debug lines for your help
  print(response.text)
  print(response.status_code)
  print(response.headers)
  </code></pre>
  <p>Getting the Output:</p>
  <pre><code>Invalid IAP credentials: Unable to parse JWT
  401
  {'X-Goog-IAP-Generated-Response': 'true', 'Date': 'Mon, 03 May 2021 06:52:11 GMT', 'Content-Type': 'text/html', 'Server': 'Google Frontend', 'Content-Length': '44', 'Alt-Svc': 'h3-29=&quot;:443&quot;; ma=2592000,h3-T051=&quot;:443&quot;; ma=2592000,h3-Q050=&quot;:443&quot;; ma=2592000,h3-Q046=&quot;:443&quot;; ma=2592000,h3-Q043=&quot;:443&quot;; ma=2592000,quic=&quot;:443&quot;; ma=2592000; v=&quot;46,43&quot;'}
  </code></pre>