title: How to return image as part of response from a GET request in Flask?
body: <p>I have a basic Python Flask API set up right not that takes an ID as a parameter for a GET request. Inside the get request logic, I am doing a get request on another resource to retrieve an image associated with the ID that was passed in:  </p>
  
  <pre><code>image = requests.get(url = image_url)
  image = Image.open(BytesIO(image.content))
  print(image.format)
  </code></pre>
  
  <p>The image format that it returns in <code>JPEG</code>.</p>
  
  <p>I want to add this as part of the response of my API. This is the definition of my GET endpoint: </p>
  
  <pre><code>@app.route('/getmsg/', methods=['GET']) 
  def respond():
  </code></pre>
  
  <p>This is how I am trying to return the image that I got from the other resource: </p>
  
  <pre><code>return {"image": send_file(image, mimetype='image/jpeg'), "data": jsonify(return_list)}
  </code></pre>
  
  <p>I already tried following this stackoverflow question: <a href="https://stackoverflow.com/questions/8637153/how-to-return-images-in-flask-response">How to return images in flask response?</a></p>
  
  <p>Which is how I got to where I am at now. I make a get request through this endpoint: <code>http://localhost:5000/getmsg/?id=7187167507933759112</code>. </p>
  
  <p>I have also tried to return just the image like so: </p>
  
  <pre><code>return send_file(image, mimetype='image/jpeg')
  </code></pre>
  
  <p>But it gives me the same error.</p>
  
  <p>Everything works except the returning of the image. </p>
  
  <p>I expect to be able to see the image in the response of the get request, but right now it gives 500 internal server error.</p>
  
  <p>This is the response that I get in the terminal: </p>
  
  <pre><code>TypeError: &lt;Response 693 bytes [200 OK]&gt; is not JSON serializable
  </code></pre>
  
  <p>Any guidance on what I am doing wrong would be greatly appreciated. Thanks.</p>