Re: POST JSON vs. urlencoded
"John P. Rouillard" <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.devel |
|---|---|
| Message-ID | <[email protected]> |
In message <[email protected]>, Ralf Schlatterbeck writes: >On Tue, Apr 02, 2019 at 06:12:39PM +0200, Ralf Schlatterbeck wrote: >> Until now I had tested POST to the REST API only with content-type >> application/x-www-form-urlencoded -- this works fine. Now I've started >> testing with application/json and I'm getting a traceback where a >> type-check on the id for a link fails in the rdbms backend with the >> message "link value must be String". > >Looks like the standard FieldStorage returns strings, not unicode and >the strings are encoded in UTF-8. The SimulateFieldStorageFromJson >returns unicode, both for the name and value attributes. >(I'm still using python2) > >At least in python2 roundup's database interface wants UTF-8 for all >strings. Can someone chime in and tell me if this has changed with >python3? I don't want to change this now and break py3 compatibility. >Unfortunately our REST tests currently don't seem to cover the different >encodings (they just call the rest methods directly). That's why I added a set of calls via dispatch, but I don't think I have any POST tests using that code path. Yeah, taking a fast look, it's all PUT or PATCH, no POST and only string data fields. No integer, float, lists (with id's). The patch I put in the response to the prior email should work with all data types (including lists of strings) supported by json except an embedded dict/object. Butdict/object is not a valid data type for the hyperdb so.... My test case was: curl -s -u demo:demo -X POST --header 'Content-Type: application/json' \ --header "Accept: application/json" \ ".../demo/rest/data/issue" \ --data '{ "title": "let rest rule the day", "status": "1", "workingorder": 3, "nosy": [ "1", "3", "5" ] }' and similar field changes for PUT on python2 and 3. Have a great evening. -- -- rouilj John Rouillard =========================================================================== My employers don't acknowledge my existence much less my opinions.