无法从Cloud Endpoints Python访问HTTP标头

时间:2014-08-23 19:14:39

标签: android python google-app-engine google-cloud-endpoints

我正在Google Cloud Endpoints中为Android应用实施自定义身份验证。为此,我在HTTP标头中发送一个身份验证令牌。来自Android:

private static final String HEADER_AUTH_TOKEN = "HTTP_AUTHORIZATION";

private GoogleClientRequestInitializer requestInitializer =
    new GoogleClientRequestInitializer() {

   @Override
   public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
      HttpHeaders headers = request.getRequestHeaders();
      if (authPrefs.authToken().exists()) {
          headers.set(HEADER_AUTH_TOKEN, authPrefs.authToken().get().toString());
      }
      request.setRequestHeaders(headers);
   }
};

Api.Builder apiBuilder = new Api.Builder(
    AndroidHttp.newCompatibleTransport(),
    new GsonFactory(),
    null);

return apiBuilder.setApplicationName(APPLICATION_NAME)
         .setGoogleClientRequestInitializer(requestInitializer)
         .build()

然后在Python中我试图检索身份验证令牌标题:

import os
auth_token = os.getenv('HTTP_AUTHORIZATION')

auth_token是无。我错过了什么?

1 个答案:

答案 0 :(得分:1)

事实证明,“HTTP_”被添加到任何发送的HTTP标头中。 HTTP_AUTHORIZATION被发送为“HTTP_HTTP_AUTHORIZATION”。