4

I have a FLASK response object that I am preparing with two string values as follows:

vioAllScript = encode_utf8(vioAllScript)
vioAllDiv = encode_utf8(vioAllDiv)
vioTup = (vioAllDiv, vioAllScript,)

resp = make_response(vioTup)
return resp

However, whenever I retrieve this response on the front end, the second value always get trimmed out of the response leaving only the first value. I have tried other options such as resp = make_response(vioAllDiv, vioAllScript) but the same thing always happens. Is there a way to get my response to contain two string values without concatenating them together?

RubyJ
  • 193
  • 2
  • 16

1 Answers1

5

Those flask interfaces are a bit too overloaded, which can be confusing. In the face of ambiguity, unfortunately, flask does not refuse the temptation to guess. If you dig into the relevant section of the docs you will find this part for calling make_response with a tuple:

Either (body, status, headers), (body, status), or (body, headers)

The second element of the tuple was not being interpreted as part of the response body.

Consider returning something like this instead:

flask.jsonify(vioAllDiv=vioAllDiv, vioAllScript=vioAllScript)
wim
  • 338,267
  • 99
  • 616
  • 750
  • This worked and returned me an object with the two values. Works perfectly for what I needed thanks! – RubyJ Aug 12 '16 at 14:19
  • 1
    @timgeb Hmm, I guess this project doesn't keep the older versions of their docs online. That stinks. I've updated to 1.1.x version, but I could not find any "latest" link. I assume the 1.1.x exhibits the same or similar enough behavior. – wim Oct 26 '20 at 16:25