Re: Errors when doing POST on a RestController

312 views
Skip to first unread message

Christophe de Vienne

unread,
Feb 14, 2013, 5:26:35 PM2/14/13
to pytho...@googlegroups.com
Hi Endre,

Le 14/02/2013 22:36, Endre Karlson a �crit :
> Source: https://github.com/woorea/billingstack/blob/master/billingstack/api/controllers/v1.py#L178-L189
>
>
> When I do a POST to this I get:
> root@svc01:~/billingstack# http -v POST
> http://localhost:9091/v1/merchants '{"name": "test"}'
>
> POST http://localhost:9091/v1/merchants
> =======================================
>
> Content-Type: application/json
>
> {
> "name": "test"
> }
>
> 400 Bad Request
> ===============
>
> Date: Thu, 14 Feb 2013 21:30:01 GMT
> Status: 400
> Content-Length: 87
> Content-Type: application/json; charset=UTF-8
> Server: WSGIServer/0.1 Python/2.7.3
>
> {
> "debuginfo": null,
> "faultcode": "Client",
> "faultstring": "Unknown argument: \"name\""
> }
>
>
> Is it not possible to get the args from the body into 1 argument?
If by that you mean sending the attributes of a unique parameter in the
body, yet you can but you have to tell it to expose first :

@[ws]expose(ReturnType, body=InputDataType)
def yourfunction(self, inputdata):
pass

This is a recent addition and it has not been properly documented yet
(it is, but on the FunctionArgument which is not a public api, and with
a different name).


Cheers,

Christophe

Christophe de Vienne

unread,
Feb 14, 2013, 5:29:04 PM2/14/13
to pytho...@googlegroups.com
Le 14/02/2013 22:36, Endre Karlson a écrit :
Source: https://github.com/woorea/billingstack/blob/master/billingstack/api/controllers/v1.py#L178-L189

I had a look at your code, you only have to replace __body__ with body.

The '__body__' name is used when calling a rest function, to pass the request body as a GET parameter.

Christophe

Endre Karlson

unread,
Feb 14, 2013, 5:43:27 PM2/14/13
to pytho...@googlegroups.com
Ok, now I tested it. See the updated version at the same thing but now I get server side:
2013-02-14 23:40:07,959 ERROR [wsme.api][MainThread] Server-side error: "list index out of range". Detail:
Traceback (most recent call last):

  File "/root/billingstack/.venv/lib/python2.7/site-packages/WSME-0.5b1-py2.7.egg/wsmeext/pecan.py", line 66, in callfunction
    pecan.request.body, pecan.request.content_type

  File "/root/billingstack/.venv/lib/python2.7/site-packages/WSME-0.5b1-py2.7.egg/wsme/rest/args.py", line 252, in get_args
    from_body = args_from_body(funcdef, body, mimetype)

  File "/root/billingstack/.venv/lib/python2.7/site-packages/WSME-0.5b1-py2.7.egg/wsme/rest/args.py", line 187, in args_from_body
    datatypes = {funcdef.arguments[-1].name: funcdef.body_type}

IndexError: list index out of range

localhost - - [14/Feb/2013 23:40:07] "POST /v1/merchants HTTP/1.1" 500 84

Client side:
(.venv)root@svc01:~/wsme# http -v POST http://localhost:9091/v1/merchants '{"name": "test", "test": "test"}'

=======================================

Content-Type: application/json

{
  "test": "test",
  "name": "test"
}

500 Internal Server Error
=========================

Date: Thu, 14 Feb 2013 22:40:07 GMT
Status: 500
Content-Length: 84
Content-Type: application/json; charset=UTF-8
Server: WSGIServer/0.1 Python/2.7.3

{
  "debuginfo": null,
  "faultcode": "Server",
  "faultstring": "list index out of range"
}



Also I looked a bit at the code and it seems that the pecan.py is missing a thing like: 
args_from_body(funcdef, request.body, request.content_type)

Can this be something that can make trouble?

Endre.

Christophe de Vienne

unread,
Apr 8, 2013, 5:03:11 AM4/8/13
to pytho...@googlegroups.com
Hi,

Sorry we did not update the group thread, but the problem was solved in the repository.

If you still have the issue, please give us details: the framework you use, some code samples or any thing that will help to understand what is going on.

Christophe

Le 08/04/2013 10:52, pawel.ko...@gmail.com a écrit :
Have someone tried to solve this problem? Server is returning the same error (list index out of range) when im trying to pass a json body (also post request). Does not work with xml body as well. Is there any fix or solution?
--
You received this message because you are subscribed to the Google Groups "python-wsme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-wsme...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

pawel.ko...@gmail.com

unread,
Apr 8, 2013, 6:33:59 AM4/8/13
to pytho...@googlegroups.com
Im using WSME 0.5b1 and Pecan framework. I want to make HTTP POST call e.g. http://127.0.0.1/test so i have defined method for that call with @wsexpose(Test, body=Test):

@wsexpose(Test, body=Test)
def post(self, input):
     test = Test()
     test.id = input.id
     return test

and Test class is:

class Test():
     name = text
     id = int

JSON which im passing in request:

{ "name"="testName",
  "id" = 1}

With standarad pecan expose (@expose) it is working correctly, but @wsexpose gives me "list index out of range". Cant find solution for that.

pawel.ko...@gmail.com

unread,
Apr 8, 2013, 7:05:31 AM4/8/13
to pytho...@googlegroups.com
I have solved my problem. The point is that the newest version of WSME installed by easy_install is 0.5b1 and this version does not contain changes from February, when bug was submitted.
Reply all
Reply to author
Forward
0 new messages