web2py: RESTful API returns "invalid arguments" for any POST request with JSON body

487 views
Skip to first unread message

Tomáš Slobodník

unread,
Nov 4, 2014, 6:48:07 AM11/4/14
to web...@googlegroups.com
Hi everyone,

I run into the following problem when implementing RESTful API.
I have this function in my controller:
@request.restful()
def prop():
    response
.view = 'generic.json'
    session
.forget(response)

   
def POST(**vars):
       
return dict()

   
return locals()

When I use cURL with valid JSON body like this one:
# curl -H "Content-Type: application/json" -d '{"client_id": 112233}' https://domain.org/api/prop

I get "invalid arguments" response.
When I send invalid JSON in request body, I get empty JSON ("{}") in response, which I assume is OK.

Can you please advice where could possibly be a problem?
I run web2py 2.9.11 on Apache and Python 2.6.1.

Thank you,
Tomas

Tomáš Slobodník

unread,
Nov 5, 2014, 3:43:56 AM11/5/14
to web...@googlegroups.com
Update:
When I run the same code locally on pre-packed Rocket web server and Python 2.7.8, no error occurs. As far as I know, web2py should still support Python 2.6.1 running on my production server. Could this be a bug or incompatibitity with python/web server/server setting?


Dne úterý, 4. listopadu 2014 12:48:07 UTC+1 Tomáš Slobodník napsal(a):

Leonel Câmara

unread,
Nov 5, 2014, 12:32:11 PM11/5/14
to web...@googlegroups.com
it should be

    def POST(*args, **vars):
        
return dict()

Not

    def POST(**vars):
        
return dict()

Tomáš Slobodník

unread,
Nov 5, 2014, 2:11:09 PM11/5/14
to web...@googlegroups.com
Hi, I already tried this, but it didn't change the behaviour.


Dne středa, 5. listopadu 2014 18:32:11 UTC+1 Leonel Câmara napsal(a):

Leonel Câmara

unread,
Nov 5, 2014, 5:12:11 PM11/5/14
to web...@googlegroups.com
Then I would guess it's some problem with your webserver configuration as there's nothing in Request.restful that wouldn't work with python 2.6 (although seriously 2.7 has been out for 4 years already).

Have you tried without using https?

Niphlod

unread,
Nov 5, 2014, 5:27:40 PM11/5/14
to web...@googlegroups.com
uuhm, I remember something going weird with python 2.6 unpacking args and kwargs, but I reeeeeally don't remember the specifics... some syntax worked in 2.6 and 2.7 while another only in 2.7

Niphlod

unread,
Nov 5, 2014, 5:37:03 PM11/5/14
to web...@googlegroups.com
whoops, don't mind. I think it's this commit that I remember, but that was back when we had 2.5 support

Tomáš Slobodník

unread,
Nov 18, 2014, 3:04:42 PM11/18/14
to web...@googlegroups.com
Ok, I tried to install Python 2.7.8 in my home directory on production server and error disappeared. Then I tried the same with Python 2.6.8 with same result - no error. Don't know what caused the error but my guess is some bug in Python 2.6.1.

Dne středa, 5. listopadu 2014 23:37:03 UTC+1 Niphlod napsal(a):
Reply all
Reply to author
Forward
0 new messages