无法让Google端点通过多种服务工作 [英] Unable to get Google endpoints working over multiple services

查看:87
本文介绍了无法让Google端点通过多种服务工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多亏了asamarin,我已经能够弄清楚如何在同一个Google App引擎中获得不同的端点(请参见

Thanks to asamarin I've been able to figure out how to get different endpoints within the same google app engine (cf Using Google endpoints in different modules of the same app).

但是我无法使其工作(至少在开发服务器中,我没有尝试将其推送到云中).我有两个模块:module1和module2,每个模块运行一个独立的api(使用google端点). 在每个moduleX/main.py中,我都有以下代码:

But I can't make it work (at least with the dev server, I've not tried to pushed it to the cloud). I have two modules: module1 and module2, each of them running an independent api (using google endpoints so). In each moduleX/main.py I have this code:

import endpoints
from protorpc import remote

# ... some code

@endpoints.api(name="moduleX", version='v0') # X being 1 or 2 obviously
class ModuleX(remote.Service):

# ... definition of the different methods

api = endpoints.api_server([ModuleX])

当我使用两个相应的模块yaml文件运行dev_appserver.py时,它们运行良好(在localhost:8080上为module1,在localhost:8081上为module2).

When I run dev_appserver.py with the two corresponding module yaml files, they start well (module1 on localhost:8080, module2 on localhost:8081).

问题来了:

  • localhost:8080/_ah/api/explore效果很好,我可以用不同的方法看到我的module1 API

  • localhost:8080/_ah/api/explore works well and I can see my module1 API with the different methods

localhost:8081/_ah/api/explore需要很长时间,然后找到与module1完全相同的API,除了单击时,它找不到方法.

localhost:8081/_ah/api/explore takes looooong time then find the exact same API than for module1 except than when I click on it, it can't find the methods.

我和Postman玩了一点儿,看看到底发生了什么,发现对localhost:8080/_ah/api/discovery/v1/apis和localhost:8081/_ah的两个调用都返回了...与discoveryRestUrl相同的信息是localhost:8080/_ah/api/discovery/v1/apis/module1/v0/rest.您会承认这很有趣.

I've played a bit with Postman to see what's going on under the wood and found out that both calls to localhost:8080/_ah/api/discovery/v1/apis and localhost:8081/_ah... return the same information with the discoveryRestUrl being localhost:8080/_ah/api/discovery/v1/apis/module1/v0/rest. Which is funny you'll admit.

我做错什么了吗?仅仅是开发服务器不能处理具有多种服务的端点吗?

Am I doing something wrong ? Is it only the dev server that doesn't handle endpoints with multiple services ?

感谢您的帮助

推荐答案

我相信这个问题仅存在于dev_appserver中,因为我和您在本地存在相同的问题,但是一旦部署,它就可以正常工作.

I believe this issue only exists with dev_appserver, as I had the same problem as you locally but it worked fine once deployed.

用于终端服务的app.yaml如下:

My app.yaml for my endpoint service looks like this:

runtime: python27
threadsafe: true
api_version: 1
service: <module-name>

handlers:
- url: /_ah/spi/.*
  script: my_script.api

libraries:
- name: pycrypto
  version: 2.6
- name: endpoints
  version: 1.0

部署后,为了打我的api,我向https://<module-name>-dot-<project-name>.appspot.com/_ah/api

Once deployed, in order to hit my api I send requests to https://<module-name>-dot-<project-name>.appspot.com/_ah/api

因此对于您提供的代码,您需要命中的端点为https://<module-name>-dot-<project-name>.appspot.com/_ah/api/<moduleX>/v0/<method> 请注意,<module-name>是在app.yaml中定义的,而<moduleX><method>将在my_script.api中的python代码中声明.

So for the code you gave, the endpoint you would need to hit would be https://<module-name>-dot-<project-name>.appspot.com/_ah/api/<moduleX>/v0/<method> Note that <module-name> is defined in app.yaml and <moduleX> and <method> would be declared in the python code in my_script.api.

为了使它在dev_appserver上本地工作,我相信您需要在自己的dev_appserver实例中运行每个终结点模块,如此处.

In order to get this working locally on dev_appserver, I believe you need to run each endpoint module in its own instance of dev_appserver, as is noted here. Admittedly I have not gotten this to work fully locally, as when I try to do this I get errors about my datastore being locked, but I believe fixing that issue should be possible as noted here.

这篇关于无法让Google端点通过多种服务工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆