title: Get Python Flask to return application/json using json.dumps
body: <p>I am using Python Flask to create a server. I want to send <code>application/json</code> back to the client (my customer requires this). When I use json.dumps() it is sending back text. </p>
  
  <p>(Incase your wondering, if I use jsonify() instead of json.dumps(), I do get application/json, however this function seems to have problems with some data (if I dont get a solution here, I will look further into jsonify)).</p>
  
  <p>server..............</p>
  
  <pre><code>import json
  from flask import Flask, render_template, url_for, current_app, request, jsonify
  
  app = Flask(__name__)
  
  @app.route("/&lt;arg1&gt;")
  def route1(arg1):
      dict1 = {"prop1": "p1", "prop2": "p2"}
      #return jsonify(dict1)      # this sends 'application/json'
      return json.dumps(dict1)  # this sends ' text/html; charset=utf-8'
  
  app.run(host="0.0.0.0", port=8080, debug=True)
  </code></pre>
  
  <p>Test client (actual client is provided by customer) ......</p>
  
  <pre><code>import pycurl
  import cStringIO
  
  SERVER_URL = "http://192.168.47.133:8080"  
  
  buf = cStringIO.StringIO()
  c = pycurl.Curl()
  
  c.setopt(c.URL, SERVER_URL + '/index.html?city=perth')
  c.setopt(c.HTTPHEADER, ['Accept:application/json']) 
  c.setopt(c.WRITEFUNCTION, buf.write)
  c.setopt(c.VERBOSE, True)
  
  c.perform()
  buf1 = buf.getvalue()
  buf.close()
  
  print(buf1)
  </code></pre>