You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reason 1 is that when type checking o[k] when k == 'rq', it's a dict and so this means both the list and string checks fail. The loop then exits and returns the message above.
Reason 2 is when you attempt to pass the POST data without specifying the application/json header. The flask framework (including the older v0.12 that we're using) behaves differently if that header is not present:
get_json(force=False, silent=False, cache=True)
Parses the incoming JSON request data and returns it. By default this function will return None if the mimetype is not application/json but this can be overridden by the force parameter. If parsing fails the on_json_loading_failed() method on the request object will be invoked.
So if you leave out the application/json header, get_json() returns None as per documentation. Code then grabs from request.form. then if k in o returns false for rq. This is because in this path, type(o) is still a dict as in problem 1 but it has the 'rq' object/string somehow shoved in as a key with an empty utf8 value, so if k in o fails and it never gets to the point of trying to convert the value in the first place (so it doesn't hit problem 1 above).
(I couldn't get a good textual output of this, so here's an image)
(versus how o is represented in the path of problem 1)
{u'rq': {u'scientificname': [...]}}
special variables:
function variables:
u'rq': {u'scientificname': [u'shortia']}
len(): 1
The text was updated successfully, but these errors were encountered:
Thanks for checking. I didn't have time to get back to it yet and I was hoping I was missing something simple.
Might be possible to do a quick fix to allow it to accept json too. Or else we can check for json and 400-something it with a message to insist the user submit form encoding.
roncanepa
changed the title
download api mishandles request when POSTing and fails to see rq/mq
download api mishandles request when POSTing json and fails to see rq/mq
Nov 6, 2020
Attempting to POST to the download api will return a message of:
This exact same json chunk works just fine when sent as a GET request.
This happens for two reasons.
https://github.com/iDigBio/idb-backend/blob/master/idb/data_api/v2_download.py#L53
Reason 1 is that when type checking
o[k]
when k == 'rq', it's adict
and so this means both thelist
andstring
checks fail. The loop then exits and returns the message above.Reason 2 is when you attempt to pass the POST data without specifying the
application/json
header. The flask framework (including the older v0.12 that we're using) behaves differently if that header is not present:https://flask.palletsprojects.com/en/0.12.x/api/
So if you leave out the
application/json
header,get_json()
returnsNone
as per documentation. Code then grabs fromrequest.form
. thenif k in o
returns false for rq. This is because in this path,type(o)
is still adict
as in problem 1 but it has the 'rq' object/string somehow shoved in as a key with an empty utf8 value, soif k in o
fails and it never gets to the point of trying to convert the value in the first place (so it doesn't hit problem 1 above).(I couldn't get a good textual output of this, so here's an image)
(versus how o is represented in the path of problem 1)
The text was updated successfully, but these errors were encountered: