Google App Engine 模块间通信授权(python)
Google App Engine inter module communication authorization (python)
引用 the problem I have is that in the Docs (communication between modules) 说:
You can configure any manual or basic scaling module to accept
requests from other modules in your app by restricting its handler to
only allow administrator accounts, specifying login: admin for the
appropriate handler in the module's configuration file. With this
restriction in place, any URLFetch from any other module in the app
will be automatically authenticated by App Engine, and any request
that is not from the application will be rejected.
这正是我名为 "api1" 的模块的配置。在我的 app.yaml 文件中我有:
# can accept requests from other modules.
# with login: admin and they are authenticated automatically.
- url: /.*
script: _go_app
login: admin
我现在正在尝试从同一应用程序中的不同模块,按照文档中的建议使用 urfetch.fetch() 方法进行服务调用,我的实现是:
from google.appengine.api import urlfetch, modules, app_identity
from rest_framework.response import Response, status
@api_view(['POST'])
def validate_email(request):
url = "http://%s/" % modules.get_hostname(module="api1")
payload = json.dumps({"SOME_KEY":"SOME_VALUE"})
appid = app_identity.get_application_id()
result = urlfetch.fetch(url + "emails/validate/document",
follow_redirects=False,
method=urlfetch.POST,
payload=payload,
headers={"Content-Type":"application/json")
return Response({
'status_code': result.status_code,
'content': result.content
}, status=status.HTTP_200_OK)
根据文档,已指定 follow_redirects=False,fetch() 将自动插入一个 header 在我的电话中(我什至试图明确添加它)与 "X-Appengine-Inbound-Appid" :MY-APP-ID。
不幸的是,作为获取调用的结果,我得到了 302 重定向,如果我遵循它,它将重定向到身份验证表单。这发生在开发服务器和生产服务器中。
你能告诉我如何在我的 validate_email 方法(属于同一应用程序中的不同模块)中调用我的 api1 服务吗?
是否有另一种方法来验证调用,因为文档中建议的方法似乎不起作用?
谢谢
如所写here this is a tracked issue now on google appengine public issue tracker。所以大家可以去那里查看更新。
与此同时,我解决了从 app.yaml 中删除 login: admin
的问题,并在我的服务处理程序中手动检查了header X-Appengine-Inbound-Appid
及其值的存在。
引用
You can configure any manual or basic scaling module to accept requests from other modules in your app by restricting its handler to only allow administrator accounts, specifying login: admin for the appropriate handler in the module's configuration file. With this restriction in place, any URLFetch from any other module in the app will be automatically authenticated by App Engine, and any request that is not from the application will be rejected.
这正是我名为 "api1" 的模块的配置。在我的 app.yaml 文件中我有:
# can accept requests from other modules.
# with login: admin and they are authenticated automatically.
- url: /.*
script: _go_app
login: admin
我现在正在尝试从同一应用程序中的不同模块,按照文档中的建议使用 urfetch.fetch() 方法进行服务调用,我的实现是:
from google.appengine.api import urlfetch, modules, app_identity
from rest_framework.response import Response, status
@api_view(['POST'])
def validate_email(request):
url = "http://%s/" % modules.get_hostname(module="api1")
payload = json.dumps({"SOME_KEY":"SOME_VALUE"})
appid = app_identity.get_application_id()
result = urlfetch.fetch(url + "emails/validate/document",
follow_redirects=False,
method=urlfetch.POST,
payload=payload,
headers={"Content-Type":"application/json")
return Response({
'status_code': result.status_code,
'content': result.content
}, status=status.HTTP_200_OK)
根据文档,已指定 follow_redirects=False,fetch() 将自动插入一个 header 在我的电话中(我什至试图明确添加它)与 "X-Appengine-Inbound-Appid" :MY-APP-ID。 不幸的是,作为获取调用的结果,我得到了 302 重定向,如果我遵循它,它将重定向到身份验证表单。这发生在开发服务器和生产服务器中。
你能告诉我如何在我的 validate_email 方法(属于同一应用程序中的不同模块)中调用我的 api1 服务吗? 是否有另一种方法来验证调用,因为文档中建议的方法似乎不起作用?
谢谢
如所写here this is a tracked issue now on google appengine public issue tracker。所以大家可以去那里查看更新。
与此同时,我解决了从 app.yaml 中删除 login: admin
的问题,并在我的服务处理程序中手动检查了header X-Appengine-Inbound-Appid
及其值的存在。