1
votes

i have a webservice which gets user requests and produces (multiple) solution(s) to this request. I want to return a solution as soon as possible, and send the remaining solutions when they are ready.

In order to do this, I thought about using Django's Http stream response. Unfortunately, I am not sure if this is the most adequate way of doing so, because of the problem I will describe below.

I have a Django view, which receives a query and answers with a stream response. This stream returns the data returned by a generator, which is always a python dictionary. The problem is that upon the second return action of the stream, the Json content breaks.

If the python dictionary, which serves as a response, is something like {key: val}, after the second yield the returned response is {key: val} {key: val}, which is not valid Json.

Any suggestions on how to return multiple Json objects at different moments in time?

1
Can you show some code? - Dalvtor
This question is a repost of a question I created yesterday, which has a bit more details. stackoverflow.com/questions/50469948/… - Rafael Marques
I can add more details, but the problem arises from yielding two dicts to a stream, so I don't believe that more details will modify the character of the problem. @Dalvtor - Rafael Marques

1 Answers

0
votes

Try decoding with something like for example

import json

json.dumps( {key: val} {key: val}, separators=('}', ':')) #check it