Using web.py for REST webservices

533 views
Skip to first unread message

chaosmaker

unread,
Aug 5, 2008, 12:55:08 PM8/5/08
to web.py
Hi all,


Someone knows if any version of web.py supports the PUT method or some
patch to support it?

I'm trying to use web.py for REST webservices, GET, POST and DELETE is
working fine, but I need the PUT method.


Thanks in advance

Aaron Swartz

unread,
Aug 5, 2008, 1:15:53 PM8/5/08
to we...@googlegroups.com
> Someone knows if any version of web.py supports the PUT method or some
> patch to support it?
>
> I'm trying to use web.py for REST webservices, GET, POST and DELETE is
> working fine, but I need the PUT method.

PUT should work fine. The default list of methods is:

./web/webapi.py: methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE']

We can add more if anyone needs them.

chaosmaker

unread,
Aug 5, 2008, 1:48:56 PM8/5/08
to web.py
I have tryed here to use the PUT method but the web.input() comes
empty.
And If I try to send the PUT request manualy after the PUT /URI HTTP/
1.0 the server closes my connection and don't accept the request body.

This is the only problem I have to use the web.py to implement one
webservice here.

Aaron Swartz

unread,
Aug 5, 2008, 1:50:32 PM8/5/08
to we...@googlegroups.com
> I have tryed here to use the PUT method but the web.input() comes
> empty.
> And If I try to send the PUT request manualy after the PUT /URI HTTP/
> 1.0 the server closes my connection and don't accept the request body.

web.input() only works if the incoming data is in key-value pairs;
usually with PUT you just get one big document so you need to call
web.data() instead.

chaosmaker

unread,
Aug 5, 2008, 1:54:12 PM8/5/08
to web.py
Right but I can send the request body to the CherryPy because it
closes the connection before the client send the request body.

For example:

caquino@suruba:~/api$ telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
PUT /REST/v1/USER/Manage/username HTTP/1.0
Content-lenght: 245

HTTP/1.1 200 OK
Date: Tue, 05 Aug 2008 17:53:18 GMT
Server: CherryPy/3.0.1

Aaron Swartz

unread,
Aug 5, 2008, 2:25:08 PM8/5/08
to we...@googlegroups.com
> Content-lenght: 245

Maybe if you spelled Content-Length correctly?

Works fine for me with 0.3:

$ telnet 0.0.0.0 8080
Trying 0.0.0.0...
Connected to 0.0.0.0.


Escape character is '^]'.

PUT / HTTP/1.0
Content-Length: 20

abcddddddddddddddd
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2008 18:24:54 GMT
Server: CherryPy/3.1.0 WSGI Server

abcddddddddddddddd
Connection closed by foreign host.

Gary Bernhardt

unread,
Aug 5, 2008, 2:28:51 PM8/5/08
to we...@googlegroups.com
On Tue, Aug 5, 2008 at 1:54 PM, chaosmaker <caq...@ebrain.com.br> wrote:
>
> Right but I can send the request body to the CherryPy because it
> closes the connection before the client send the request body.
>
> For example:
>
> caquino@suruba:~/api$ telnet 127.0.0.1 8080
> Trying 127.0.0.1...
> Connected to 127.0.0.1.
> Escape character is '^]'.
> PUT /REST/v1/USER/Manage/username HTTP/1.0
> Content-lenght: 245

You misspelled Content-length, which is probably the problem since
without it, the server doesn't know how much data to expect.

> HTTP/1.1 200 OK
> Date: Tue, 05 Aug 2008 17:53:18 GMT
> Server: CherryPy/3.0.1

--
Gary
http://blog.extracheese.org

chaosmaker

unread,
Aug 5, 2008, 2:42:01 PM8/5/08
to web.py
Sorry about the mistake, but for me using the right one give me the
same result.

But I have noticed one difference in your output
Server: CherryPy/3.0.1
Server: CherryPy/3.1.0 WSGI Server

I think this is the problem, I'm using the web.py from the debian
package, can this be the problem?

On Aug 5, 3:28 pm, "Gary Bernhardt" <gary.bernha...@gmail.com> wrote:

chaosmaker

unread,
Aug 5, 2008, 3:25:58 PM8/5/08
to web.py
I have tryed to use the svn version, but the CherryPy used on it does
not work in the python 2.5 debian package because of some changes in
the cStringIO module.

chaosmaker

unread,
Aug 5, 2008, 3:37:05 PM8/5/08
to web.py
I'm sorry again, the web.data works with 3.0.1 too.
Sorry about bother.

Thanks for the help!

On Aug 5, 3:42 pm, chaosmaker <caqu...@ebrain.com.br> wrote:

paul jobs

unread,
Aug 5, 2008, 6:45:53 PM8/5/08
to we...@googlegroups.com
what is web.data()

Yoan Blanc

unread,
Aug 6, 2008, 4:23:19 AM8/6/08
to we...@googlegroups.com
I had to do that modification for PUT:

=== modified file 'web/webapi.py'
--- web/webapi.py 2008-06-28 15:43:14 +0000
+++ web/webapi.py 2008-07-26 21:51:40 +0000
@@ -170,8 +170,8 @@
e = ctx.env.copy()
a = b = {}

- if _method.lower() in ['both', 'post']:
- if e['REQUEST_METHOD'] == 'POST':
+ if _method.lower() in ['both', 'post', 'put']:
+ if e['REQUEST_METHOD'] in ['POST', 'PUT']:
if e.get('CONTENT_TYPE', '').lower().startswith('multipart/'):
# since wsgi.input is directly passed to cgi.FieldStorage,
# it can not be called multiple times. Saving the FieldStorage

I dunno if it's the right way or if that has already been done elsewhere.

--
Yoan

Aaron Swartz

unread,
Sep 19, 2008, 6:37:47 PM9/19/08
to we...@googlegroups.com
Isn't that in web.input? Are people PUTting form data? I guess that
could make sense; file a bug if that's what you're doing.

Anand Chitipothu

unread,
Sep 19, 2008, 8:41:52 PM9/19/08
to we...@googlegroups.com
On Sat, Sep 20, 2008 at 4:07 AM, Aaron Swartz <m...@aaronsw.com> wrote:
>
> Isn't that in web.input? Are people PUTting form data? I guess that
> could make sense; file a bug if that's what you're doing.

Already fixed.

Reply all
Reply to author
Forward
0 new messages