Cannot make Helloworld example work...

117 views
Skip to first unread message

Dr. Funk

unread,
Oct 22, 2012, 6:24:47 PM10/22/12
to google-prot...@googlegroups.com
Hello there!

I'm new to web development but I've worked with Python for some time now.
I've been studying GAE documentation now ProtoRPC.
I can't get the first example to work despite numerous attempts (sigh...).
Could somebody tell me what I'm doing wrong?

I basically copied the ProtoRPC Helloword example code in a helloworld.py file.
I then created an app.yaml file with the following content:

application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /hello
  script: helloworld.py

I'm running my app through GAE Launcher.
When I try to post a message with curl in the command line.
I've tried different curl arguments:

curl -H 'content-type:text' -d 'Tom' http://localhost:8080/hello
No answer in the CL.
GAE Launcher logs says : INFO     2012-10-22 22:19:22,030 dev_appserver.py:3056] "POST /hello HTTP/1.1" 200 -
curl -H 'content-type:application/json' -d '{"text": "Tom"}' http://localhost:8080/hello
Error message in the CL : curl: (3) [globbing] unmatched close brace/bracket at pos 4.
GAE Launcher logs says : INFO     2012-10-22 22:20:19,875 dev_appserver.py:3056] "POST /hello HTTP/1.1" 200 -
curl -H 'content-type:application/json' -d '{"my_name": "Tom"}' http://localhost:8080/hello
Error message in the CL : curl: (3) [globbing] unmatched close brace/bracket at pos 4.
GAE Launcher logs says : INFO     2012-10-22 22:21:39,765 dev_appserver.py:3056] "POST /hello HTTP/1.1" 200 -

So here I am. What am I doing wrong? I could use a little help...

Thanks in advance!

Rafe Kaplan

unread,
Oct 30, 2012, 10:39:50 PM10/30/12
to google-prot...@googlegroups.com
It looks like you have not specified the "hello" path properly. You
should probably configure it this way in app.yaml:

handlers:
- url: /hello.*
script: helloworld.py


Notice that the path is now terminated with .* allowing that handler
to recognize method names.

It also looks like the requests you are making do not reference
method names. Have you defined any methods in helloworld.py?
--
- Rafe Kaplan
Message has been deleted

Dr. Funk

unread,
Nov 5, 2012, 8:09:04 AM11/5/12
to google-prot...@googlegroups.com
Hello Rafe,

thanks for answering my message! Sorry I couldn't answer anytime sooner, I was on vacation last week =)

I tried modifying the app.yaml file as you said, and tried making request with method names (for instance http://localhost:8080/hello.HelloService.hello()).
Unfortunately I still get the same answers to my requests.

I have defined a hello method in helloworld.py, it's really the same code than in the Helloworld example :

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)])

I have to say, I'm a bit confused by the code... What does "package" stand for? Is it suppose to be the name of the Python package and therefore the name of the directory containing the project?

Rafe Kaplan

unread,
Nov 5, 2012, 7:35:36 PM11/5/12
to google-prot...@googlegroups.com
>
> thanks for answering my message! Sorry I couldn't answer anytime sooner, I
> was on vacation last week =)
>
> I tried modifying the app.yaml file as you said, and tried making request
> with method names (for instance
> http://localhost:8080/hello.HelloService.hello()).

The name of the service is not used in the creation of the path. If
your service has a method called hello, the URL would be:

http://localhost:8080/hello.hello

To summarize it's of the form:

http://<host-port>/<service-path>.<method-name>


> Unfortunately I still get the same answers to my requests.
>
> I have defined a hello method in helloworld.py, it's really the same code
> than in the Helloworld example :
>
> 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)])

The path should just be "/hello" not "/hello.*". The app.yaml file
needs to have the .* because it's a general purpose routing mechanism.
The path given to service_mapping is specific to ProtoRPC so the
regular expression is already defined for it. It's a little confusing
to have two places where paths are mapped, but unfortunately this is
true of all App Engine applications.

>
> I have to say, I'm a bit confused by the code... What does "package" stand
> for? Is it suppose to be the name of the Python package and therefore the
> name of the directory containing the project?

The package is a namespace mechanism that comes from Google protocol
buffers. ProtoRPC also uses it for clients that are automatically
generating the client classes based on the RegistryService. In this
case it will map package name to module name.


--
- Rafe Kaplan
Message has been deleted

Dr. Funk

unread,
Nov 6, 2012, 4:29:46 PM11/6/12
to google-prot...@googlegroups.com
Hey!

I tried sending requests to http://localhost:8080/hello.hello, without much success...


> app = service.service_mappings([('/hello.*', HelloService)])
Concerning the path mapping, I just copied the HelloWorld example, so it must be wrong. I tried to modify it according to your answer, but it didn't work.
This is the bottom of the problem really, I just cannot make this example work as described in the documentation.

And concerning the package name, my directory and .py file were named "helloworld", so I also tried renaming them to "hello" (and modifying the app.yaml file accordingly), but it still doesn't work.
I kinda running out of ideas...

I'm really thankful that you're helping me out, it's just that there's nothing more frustrating than a badly written documentation where you cannot get past the first example without help when you're a beginner... :(

Rafe Kaplan

unread,
Nov 7, 2012, 7:01:48 PM11/7/12
to google-prot...@googlegroups.com
I understand. I'm sorry for the confusion. Will try to fix the
documentation soon.
--
- Rafe Kaplan

Dr. Funk

unread,
Nov 8, 2012, 4:40:08 AM11/8/12
to google-prot...@googlegroups.com
Thanks so much for your time Rafe, I really want to learn to use this library and I appreciate your help =)

Rafe Kaplan

unread,
Nov 8, 2012, 11:38:58 PM11/8/12
to google-prot...@googlegroups.com
If you are still willing to stick with it, I really appreciate it!
I've copied your code and tried it out. I noticed that you are
writing a Python 2.5 application. You probably ought to be writing in
Python 2.7 but if you are want to use Python 2.5, it uses CGI instead
of WSGI. This means your code needs to have a main function like
here:

http://code.google.com/p/google-protorpc/
=================================
from google.appengine.ext.webapp import util

def main():
util.run_wsgi_app(app)

if __name__ == '__main__':
main()


Did you intend to use 2.5? The App Engine Python 2.5 runtime is deprecated.

On Thu, Nov 8, 2012 at 1:40 AM, Dr. Funk <clement.c...@gmail.com> wrote:
> Thanks so much for your time Rafe, I really want to learn to use this
> library and I appreciate your help =)



--
- Rafe Kaplan

dansalmo

unread,
Nov 10, 2012, 3:13:02 PM11/10/12
to google-prot...@googlegroups.com
I encountered the same issues that you have with the helloworld example.  It is not a true example in the way the previous app engine examples are.  It is just an incomplete code fragment and getting it working will still leave you with a lot of open questions.

The guestbook example is closer to a full working example but also needs changes before it will work for you.  I spent a few hours at least figuring it out and posted the changes needed here:
https://groups.google.com/forum/?fromgroups=#!topic/google-protorpc-discuss/-8fjzWbEb0k

Once you get it working and then start to expand on it, it will start to make more sense.  If all you want to do is ajax type requests with app engine, you may want to look at using jquery .load() instead.  You can use it with the standard urls in the webapp framework and it easy to implement on the client side.

Dan

Dr. Funk

unread,
Nov 13, 2012, 7:01:23 AM11/13/12
to google-prot...@googlegroups.com
@Rafe
Yes, I am willing to stick with it =)
I am writing a Python 2.7 application. I don't have a main function because I just copied the code of the documentation (https://developers.google.com/appengine/docs/python/tools/protorpc/overview) and it is different from the one on google code. I'll check the google code version tonight, maybe it'll solve things!

@Dan
Thanks for the tip Dan, I'll move on to the guestbook example soon and I'll check your updated tutorial =)

Julio Cezar Novais Raffaine

unread,
Dec 6, 2012, 9:13:06 PM12/6/12
to google-prot...@googlegroups.com
I also cannot make any attempt of this ProtoRPC to work.

My Hello World app returns always this Bad Request and I even tried to make the Request a Void Message (no luck)

I'm using the Google Developers Reference as it looks the most updated, and I downloaded GAE right now.

Here is my code:

from protorpc import messages
from protorpc import message_types
from protorpc import remote
from protorpc.wsgi import service

package = 'hello'

# Create the request string
class HelloRequest(messages.Message):
my_name = messages.StringField(1, required=True)
class HelloResponse(messages.Message):
hello = messages.StringField(1, required=True)
class HelloService(remote.Service):
@remote.method(HelloRequest, HelloResponse)
def hello(self, request):
return HelloResponse(hello='Hello there, %s!'%request.my_name)
app = service.service_mappings([('/hello',HelloService)])

It's under folder king (I don't know if this matters), and here is the app.yaml:

application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /hello.*
  script: helloworld.app
  
- url: /protorpc.*
  script: helloworld.app

I tried to use the Form to test but when I put the /form in my URL I get a "Not Found" in the face.

I really want to make this work but I'm giving up ... it's to hard to make the hello world work. And it's been hard to test it.

Here is the curl command line I also tried (I'm using Windows):
curl.exe -H 'Content-Type:application/json' --data '{my_name:Julio}' http://loca
lhost:8080/hello.hello

No luck ... "Unsupported Media Type" in the face.
Reply all
Reply to author
Forward
0 new messages