title: AppEngine - Remote API returning 401 and too-many-auth
body: <p>I am trying to connect to an AppEngine instance with the remote API with something like this:</p>
  
  <pre><code>os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = ".../path/to/key"
  remote_api_stub.ConfigureRemoteApiForOAuth(
      server.encode('ascii'), path, secure=True
  )
  </code></pre>
  
  <p>Where the <code>path/to/key</code> points to a JSON file created in the Google Cloud (Beta), <strong>API Manager -> Credentials -> Add Credentials -> Service Account</strong>.  The service account "Can edit" per the <strong>Permissions</strong> panel.</p>
  
  <p>When I run this I get an error like this on the console, corresponding to a 401 (as reported in the App Engine log viewer):</p>
  
  <pre>
    File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 768, in ConfigureRemoteApiForOAuth
      rpc_server_factory=rpc_server_factory)
    File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 835, in ConfigureRemoteApi
      app_id = GetRemoteAppIdFromServer(server, path, rtok)
    File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 569, in GetRemoteAppIdFromServer
      response = server.Send(path, payload=None, **urlargs)
    File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 258, in Send
      NeedAuth()
    File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 234, in NeedAuth
      RaiseHttpError(url, response_info, response, 'Too many auth attempts.')
    File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 85, in RaiseHttpError
      raise urllib2.HTTPError(url, response_info.status, msg, response_info, stream)
  urllib2.HTTPError: HTTP Error 401: Unauthorized Too many auth attempts.
  </pre>
  
  <p>I checked and the correct credentials seem to be set in <code>/google/appengine/ext/remote_api/remote_api_stub.py:760</code> and should be passed to the remote api.</p>
  
  <p>The <code>app.yaml</code> has the basic setting <code>- remote_api: on</code> under <code>builtins</code>.</p>
  
  <p>This setup works for the local <code>dev_appserver.py</code>, so I am led to believe the problem is on the Google server/cloud settings.</p>
  
  <p>I have tried both authentication schemes in <strong>App Engine -> Settings -> Application settings</strong> (Google Accounts API and Google Apps domain).</p>
  
  <p>I followed the <a href="https://developers.google.com/identity/protocols/application-default-credentials" rel="noreferrer">Google Application Default Credentials</a> as fit as I could, but maybe I missed something?</p>
  
  <p>It is probably also worth noting that from the command line:</p>
  
  <pre><code>$ GOOGLE_APPLICATION_CREDENTIALS=~/path-to-key
      remote_api_shell.py -s APPID.appspot.com --secure APPID
  </code></pre>
  
  <p>also gives the same 401 exception.</p>