Response streamed [200 OK]> is not JSON serializable stream image python
<p>I am looking for a way to serve some images from the bing map without sharing the URL (because it contains the secret key) and return it to the client (without saving to disk first).  I'm using this method from <a href="http://flask.pocoo.org/snippets/118/" rel="nofollow">here</a></p>

<pre><code>def get_stream_from_url(url):
    req = requests.get(url, stream = True)
    return Response(stream_with_context(req.iter_content()), content_type = req.headers['content-type'])
</code></pre>

<p>I use it in another method, where I generate a list with those info for those image, so basically I wan to put the  sream response inside the json as a value of key <code>url</code>: </p>

<pre><code>   def images_data_and_url(self, data):
        results = []
        for i in range(1, 13):
            image = {}
            description = data['description']
            url = self.get_stream_from_url(data['url'])
            tile = {"description": description
                    "url": url}
           results.append(image)
        print results
        return json.dumps(results)
</code></pre>

<p>EDIT: 
If I print the results I have this:</p>

<pre><code>&lt;type 'list'&gt;: [{'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;} , {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;},{'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}, {'description': ' this is an example', 'url': &lt;Response streamed [200 OK]&gt;}]
</code></pre>

<p>If I do like this I get this error </p>

<pre><code>&lt;Response streamed [200 OK]&gt; is not JSON serializable
</code></pre>

<p>This because of the function <code>get_stream_from_url</code> returns a response :/ My problem is that I don't know how to send it in another way? </p>

<p>In HTML I get the data and assign per the data for each image like this:</p>

<pre><code>&lt;img class="image1 " data-description="The description" src=""&gt;
</code></pre>

<p>Can somebody help me, how to encode the stream so I can send it as with the JSON data?</p>

<p>There is no need to hide a Bing Maps key. Anyone can create on and use it under the free terms of use. As such there is little incentive for them to steal your key. In majority of cases where a key appeared to be stolen, the root cause was code being handed off that contained the key or the key being posted in code samples in forum posts. The user of the key usually were unaware of the key in the code. The Bing Maps team is able to track these situations and resolve them as needed. That said it rarely occurs. Generally, when someone wants to steal a Bing Maps key, they just use the key from the Bing Maps website.</p>

python json python-2.7 bing-maps bing