我一直在尝试使用相当简单的Hello World ProtoRPC App Engine示例,但无济于事。不幸的是,网站上的代码似乎不起作用。我已经查看了许多可能的解决方案,但找不到完整的工作集。任何帮助将非常感激!您可以在下面看到错误(或缺少错误):
的app.yaml
application: proto-test
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /hello.*
script: hello.py
hello.py
from protorpc import messages
from protorpc import remote
from protorpc.wsgi import service
package = 'hello'
# Create the request string containing the user's name
class HelloRequest(messages.Message):
my_name = messages.StringField(1, required=True)
# Create the response string
class HelloResponse(messages.Message):
hello = messages.StringField(1, required=True)
# Create the RPC service to exchange messages
class HelloService(remote.Service):
@remote.method(HelloRequest, HelloResponse)
def hello(self, request):
return HelloResponse(hello='Hello there, %s!' % request.my_name)
# Map the RPC service and path (/hello)
app = service.service_mappings([('/hello', HelloService)])
卷曲命令
curl -H 'content-type:application/json' -d '{"my_name":"test1"}' http://proto-test.appspot.com/hello.hello
当我在命令行中运行上面的命令时,它只返回提示而没有错误。我的日志表明curl命令有点奏效,但它没有提供响应。这是日志中出现的内容:
2013-05-08 22:27:07.409 /hello.hello 200 522ms 0kb curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
2620:0:10c8:1007:a800:1ff:fe00:33af - - [08/May/2013:14:27:07 -0700] "POST /hello.hello HTTP/1.1" 200 0 - "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" "proto-test.appspot.com" ms=523 cpu_ms=133 loading_request=1 app_engine_release=1.8.0 instance=00c61b117c66197ad84ad9bc61485b292e5129
I 2013-05-08 22:27:07.409
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
通过Chrome JS控制台进行的Ajax调用返回以下内容: SyntaxError:意外的令牌ILLEGAL :
$.ajax({url: ‘/hello.hello’, type: 'POST', contentType: 'application/json', data: ‘{ "my_name": "Bob" }’,dataType: 'json',success: function(response){alert(response.hello);}});
答案 0 :(得分:1)
您发布的Java脚本似乎有语法错误。主要是,看起来你在地方使用`字符而不是'字符。
您的请求无效的原因是您编写app.yaml文件的方式。您正在使用旧的Python 2.5方法通过引用脚本而不是WSGI应用程序来调用应用程序。您可以通过将app.yaml中的url处理程序更改为:
来更正它处理程序: - url:/hello.* 脚本:hello.app