[ish.io] 404 Not Found

1 view
Skip to first unread message

SamG

unread,
Apr 23, 2010, 3:00:17 AM4/23/10
to ish.io
I am a little baffled at the moment here is my code.

import logging
from restish import http, resource, app
from gevent import wsgi

log = logging.getLogger(__name__)

class Root(resource.Resource):
@resource.child()
def o3(self, request, segments):
return O3()

class O3(resource.Resource):

@resource.child()
def o3(self, request, segments):
return self.o3process

@resource.POST()
def o3process(self,request):
rspxml = "<human><head>Hello</head></human>"
print rspxml
return http.ok([('Content-Type', 'text/xml')],rspxml)

application = app.RestishApp(Root())
wsgi.WSGIServer(('', 8080), application, spawn=None).serve_forever()

What i do from the RESTClient(A firefox addon) i do POST on
http://127.0.0.1/o3 and i get the following response.

127.0.0.1 - - [2010-04-23 12:27:04] "POST /o3 HTTP/1.1" 200 33 "-"
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100405
Firefox/3.6.3 (Swiftfox)"

But when i do a post on http://127.0.0.1/o3/ i get an 404 not found.

127.0.0.1 - - [2010-04-23 12:24:34] "POST /o3/ HTTP/1.1" 404 13 "-"
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100405
Firefox/3.6.3 (Swiftfox)"

What i tried using the @resource.child(resource.any) on the O3.o3 but
with the same result. What am i doing wrong?

Sam

--
You received this message because you are subscribed to the Google Groups "ish.io" group.
To post to this group, send an email to is...@googlegroups.com.
To unsubscribe from this group, send email to ishio+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ishio?hl=en-GB.

SamG

unread,
Apr 23, 2010, 3:48:51 AM4/23/10
to ish.io
Well,

Found the answers here. http://groups.google.com/group/ishio/browse_frm/thread/f432f55b8b0ede18?tvc=1&q=404

Loving restish.

Sam

On Apr 23, 12:00 pm, SamG <mad.vi...@gmail.com> wrote:
> I am a little baffled at the moment here is my code.
>
> import logging
> from restish import http, resource, app
> from gevent import wsgi
>
> log = logging.getLogger(__name__)
>
> class Root(resource.Resource):
>     @resource.child()
>     def o3(self, request, segments):
>         return O3()
>
> class O3(resource.Resource):
>
>     @resource.child()
>     def o3(self, request, segments):
>         return self.o3process
>
>     @resource.POST()
>     def o3process(self,request):
>         rspxml = "<human><head>Hello</head></human>"
>         print rspxml
>         return http.ok([('Content-Type', 'text/xml')],rspxml)
>
> application = app.RestishApp(Root())
> wsgi.WSGIServer(('', 8080), application, spawn=None).serve_forever()
>
> What i do  from the RESTClient(A firefox addon) i do  POST onhttp://127.0.0.1/o3and i get the following response.
>
> 127.0.0.1 - - [2010-04-23 12:27:04] "POST /o3 HTTP/1.1" 200 33 "-"
> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100405
> Firefox/3.6.3 (Swiftfox)"
>
> But when i do a post onhttp://127.0.0.1/o3/i get an 404 not found.
>
> 127.0.0.1 - - [2010-04-23 12:24:34] "POST /o3/ HTTP/1.1" 404 13 "-"
> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100405
> Firefox/3.6.3 (Swiftfox)"
>
> What i tried using the @resource.child(resource.any) on the O3.o3 but
> with the same result. What am i doing wrong?
>
> Sam
>
> --
> You received this message because you are subscribed to the Google Groups "ish.io" group.To post to this group, send an email toi...@googlegroups.com.To unsubscribe from this group, send email toishio+u...@googlegroups.com.

Yoan Blanc

unread,
Apr 23, 2010, 3:57:05 AM4/23/10
to is...@googlegroups.com
2010/4/23 SamG <mad....@gmail.com>:
> I am a little baffled at the moment here is my code.
>
> import logging
> from restish import http, resource, app
> from gevent import wsgi
>
> log = logging.getLogger(__name__)
>
> class Root(resource.Resource):
>    @resource.child()
>    def o3(self, request, segments):
>        return O3()
>
> class O3(resource.Resource):
>
>    @resource.child()
>    def o3(self, request, segments):
>        return self.o3process

wtf?

>
>    @resource.POST()
>    def o3process(self,request):
>        rspxml = "<human><head>Hello</head></human>"
>        print rspxml
>        return http.ok([('Content-Type', 'text/xml')],rspxml)

$ curl -X POST http://localhost:8080/o3
<human><head>Hello</head></human>

> application = app.RestishApp(Root())
> wsgi.WSGIServer(('', 8080), application, spawn=None).serve_forever()
>
> What i do  from the RESTClient(A firefox addon) i do  POST on
> http://127.0.0.1/o3 and i get the following response.
>
> 127.0.0.1 - - [2010-04-23 12:27:04] "POST /o3 HTTP/1.1" 200 33 "-"
> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100405
> Firefox/3.6.3 (Swiftfox)"
>
> But when i do a post on http://127.0.0.1/o3/ i get an 404 not found.

Logical :-)

class Foo(resource.Resource):
@resource.GET()
def get(self, request):
"""/foo"""
# …

@resource.child("")
def dir(self, request, segments):
"""/foo/ -> /foo"""
return http.found(request.url.parent())

class Root(resource.Resource):
@resource.child()
def foo(self, request, segments):
return Foo(), segments

Because function get decorated, it seems very difficult to reuse them
from another one, you'll have to create a third one I assume. Anyways,
it looks weird.

This because of how REST design what a resource is:

/books/ -> a collection of books
/a-book -> a book

http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services

Cheers,

--
Yoan

Nathan Davis

unread,
Apr 26, 2010, 11:07:24 AM4/26/10
to is...@googlegroups.com
On Fri, Apr 23, 2010 at 2:00 AM, SamG <mad....@gmail.com> wrote:
I am a little baffled at the moment here is my code.

import logging
from restish import http, resource, app
from gevent import wsgi

log = logging.getLogger(__name__)

class Root(resource.Resource):
   @resource.child()

This should be @resource.child("o3")
 
   def o3(self, request, segments):
       return O3()

class O3(resource.Resource):

   @resource.child()
   def o3(self, request, segments):
       return self.o3process


It's probably better to return self here.  That way HTTP methods get routed to the correct method on the object.
 

Matt Goodall

unread,
Apr 26, 2010, 11:27:42 AM4/26/10
to is...@googlegroups.com
On 26 April 2010 16:07, Nathan Davis <davis...@gmail.com> wrote:
> On Fri, Apr 23, 2010 at 2:00 AM, SamG <mad....@gmail.com> wrote:
>>
>> I am a little baffled at the moment here is my code.
>>
>> import logging
>> from restish import http, resource, app
>> from gevent import wsgi
>>
>> log = logging.getLogger(__name__)
>>
>> class Root(resource.Resource):
>>    @resource.child()
>
> This should be @resource.child("o3")

Actually, a plain @resource.child() uses the name of the method so, in
affect, they're both the same but using the method name means you
don't have to repeat yourself.

>
>>
>>    def o3(self, request, segments):
>>        return O3()
>>
>> class O3(resource.Resource):
>>
>>    @resource.child()
>>    def o3(self, request, segments):
>>        return self.o3process
>>
>
> It's probably better to return self here.  That way HTTP methods get routed
> to the correct method on the object.

Good point.

To be honest, I wasn't really sure what that code was doing anyway. I
assumed that was what Yoan's "wtf?" was all about ;-).

- Matt
Reply all
Reply to author
Forward
0 new messages