当服务器绑定到特定IP(而非本地主机)时,如何使Google App Engine python SDK远程API与本地开发服务器配合使用? [英] How do I make Google App Engine python SDK Remote API work with local development server when server is bound to specific IP (not localhost)?
问题描述
在生产服务器上使用远程api(remote_api_shell.py
)可以正常工作.但是,仅当开发服务器在localhost
上提供服务时,它才能在开发服务器上工作.当服务器在特定IP(例如,dev_appserver.py --host=192.168.0.1
)上运行时,它将不起作用.
Using the remote api (remote_api_shell.py
) works fine on the production server. However, it only works on the development server when the development server is serving on localhost
. It does not work when the server is running on specific IP (for example, dev_appserver.py --host=192.168.0.1
).
这是使用Python SDK的.我敢肯定这适用于版本1.7.5
.它不适用于1.7.6
或1.8.0
.
This is using the Python SDK. I'm kinda sure this worked on version 1.7.5
. It does not work on 1.7.6
or 1.8.0
.
这是一个具体情况:
运行服务器,并使其绑定到默认地址(localhost:8080
):
Run the server and let it bind to the default address (localhost:8080
):
/path/to/dev_appserver.py myapp/app.yaml
INFO 2013-05-25 19:11:15,071 sdk_update_checker.py:244] Checking for updates to the SDK.
INFO 2013-05-25 19:11:15,323 api_server.py:152] Starting API server at: http://localhost:39983
INFO 2013-05-25 19:11:15,403 dispatcher.py:98] Starting server "default" running at: http://localhost:8080
INFO 2013-05-25 19:11:15,405 admin_server.py:117] Starting admin server at: http://localhost:8000
启动远程API shell,它可以正常工作:
Start the remote API shell, and it works fine:
$ ./remote_api_shell.py -s localhost:8080
Email: x@x
Password:
App Engine remote_api shell
Python 2.7.2+ (default, Jul 20 2012, 22:15:08)
[GCC 4.6.1]
The db, ndb, users, urlfetch, and memcache modules are imported.
dev~furloughfun>
但是,如果您使用指定的主机启动服务器:
However, if you start the server with a specified host:
/path/to/dev_appserver.py --host=192.168.0.1 myapp/app.yaml
INFO 2013-05-25 19:11:53,304 sdk_update_checker.py:244] Checking for updates to the SDK.
INFO 2013-05-25 19:11:53,554 api_server.py:152] Starting API server at: http://localhost:44650
INFO 2013-05-25 19:11:53,633 dispatcher.py:98] Starting server "default" running at: http://192.168.0.1:8080
INFO 2013-05-25 19:11:53,634 admin_server.py:117] Starting admin server at: http://localhost:8000
请注意,即使内容在http://192.168.0.1:8080
中提供,它也会显示Starting API server at: http://localhost:44650
.这是否表明您可以仅在本地主机上运行远程api?也许出于安全原因?
Notice it says Starting API server at: http://localhost:44650
even though the content is served at http://192.168.0.1:8080
. Is this indicative that you can only run the remote api on localhost? Perhaps for security reasons?
此外,当您现在尝试remote_api_shell.py
时,您只能使用有效帐户登录(不允许使用虚假帐户),并且该错误立即终止并终止.
Also, when you try the remote_api_shell.py
now, you can only log in with a valid account (no bogus accounts allowed) and it immediately errors and terminates.
控制台错误以
urllib2.HTTPError: HTTP Error 200: OK
和本地开发服务器输出:
and the local development server outputs:
INFO 2013-05-25 19:24:06,674 server.py:528] "GET /_ah/remote_api?rtok=90927106532 HTTP/1.1" 401 57
有人知道这是怎么回事吗?
除了在localhost
上,是否可以访问远程API?
如果您的内容是在特定IP上提供的,是否不可能访问远程API(甚至在localhost
上)?
Anyone know what's going on here?
Is it impossible to access the remote API other than on localhost
?
Is it impossible to access the remote API (even on localhost
) if your content is served on a specific IP?
推荐答案
似乎api服务器没有设置主机的选项. dev_appserver.py
具有用于设置主机&的选项.内容和管理服务器的端口,以及api服务器专用的端口(api_port
选项).示例:
It seems that api server doesn't have option to set host. dev_appserver.py
has options to set host & port for content and admin server, and for api server only port (api_port
option). Example:
dev_appserver.py --host=192.168.5.92
--admin_host 192.168.5.92 --admin_port 9000
--api_port 7000 .
运行此报告:
api_server.py:153] Starting API server at: http://localhost:7000
dispatcher.py:164] Starting server "default" running at: http://192.168.5.92:8080
admin_server.py:117] Starting admin server at: http://192.168.5.92:9000
查看GAE dev_appserver的源代码,启动服务器的api_server方法的调用方是模块devappserver2.py
,其行是:
Looking into the source of GAE dev_appserver, caller of the method of api_server which starts the server is module devappserver2.py
and the line is:
apis = api_server.APIServer('localhost', options.api_port,
configuration.app_id)
您可以看到硬编码的主机名localhost
.
You can see hardcoded host name localhost
.
If you find no good workaround, I would suggest to patch devappserver2.py
by introducing a new option and report issue with patch attached?
这篇关于当服务器绑定到特定IP(而非本地主机)时,如何使Google App Engine python SDK远程API与本地开发服务器配合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!