gluon.globals.Request parsing behavior for array with length 1

25 views
Skip to first unread message

Kio Kim

unread,
Jul 9, 2015, 8:46:52 AM7/9/15
to web...@googlegroups.com
In gluon.globals, I found a behavior that I don't understand, and that gives me an headache.

class Request(Storage):
...
def parse_post_vars(self):
...
if len(pvalue): post_vars[key] = (len(pvalue) > 1 and pvalue) or pvalue[0]


The above underlined line is what I am talking about. When the browser post a json object with an array, if the array length is 1, it simply returns the first argument and denatures the array property. Also, the key of the object is appended '[]'. For example, when I submit {'key':['value1']}, what I get in request.post_vars is {'key[]':'value1'}.

Is it an intended behavior, or a bug? I am not sure whether this question belongs to web2py-users or web2py-dev; posting here hoping this is a well-known issue. 

Thanks in advance for any response!

Yebach

unread,
Jul 27, 2016, 6:01:57 AM7/27/16
to web2py-users
Did you menage to solve this. I am facing the same issue here and it is killing me.

Massimo Di Pierro

unread,
Jul 27, 2016, 6:16:16 AM7/27/16
to web2py-users
You need to set the content-type = 'application/json' when you POST json content. Else web2py does not know it is json and inteprets is incorrectly as a multipart form.
Reply all
Reply to author
Forward
0 new messages