POST JSON vs. urlencoded

Ralf Schlatterbeck <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.devel
Message-ID <[email protected]>
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".
Now it turns out, the check there compares the value it gets to type('')
but gets a unicode id from the REST API. The RDBMS backend (at least in
Python2) should get UTF-8 encoded strings, not unicode. So my guess is
that somewhere in the guts of the REST API there is a decode() step
missing.

Example working POST (urlencoded) (deleted some headers):

POST /job-log/rest/data/issue HTTP/1.1
User-Agent: python-requests/2.12.4
Content-Length: 179
Content-Type: application/x-www-form-urlencoded

status=waiting-for-confirmation&customer=1505609&demo_rq_id=4711081542421&title=Noch+ein+test&messages=228&priority=normal&salesperson=22&org_link=1&crm_requester=22&opportunity=1

Exampe not-working POST (json) (deleted some headers):
POST /job-log/rest/data/issue HTTP/1.1
User-Agent: python-requests/2.12.4
Content-Length: 233
Content-Type: application/json

{"status": "waiting-for-confirmation", "customer": "3", "demo_rq_id": "471108154242", "title": "Noch ein test", "messages": "228", "priority": "normal", "salesperson": "22", "org_link": "1", "crm_requester": "22", "opportunity": "1"}


When using the python request library, reproducing this is simple:
I prepare the value dictionary and the I either use

session = requests.session()
session.auth = (username, password)

d = dict (...)

# for the urlencoded payload:
r = session.post (url + 'issue', data = d)
#for the JSON payload:
r = session.post (url + 'issue', json = d)


Did anyone already test modifying methods (POST, PUT, PATCH) with a json
payload?

John, how did you test so far?

Ralf
-- 
Dr. Ralf Schlatterbeck                  Tel:   +43/2243/26465-16
Open Source Consulting                  www:   http://www.runtux.com
Reichergasse 131, A-3411 Weidling       email: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.