TypeError: Expected bytes in Flask app
<p>I am trying to implement a simple flask app which will pass a json file to the front end, but got an error as following:</p>

<pre><code>&gt; 127.0.0.1 - - [04/Oct/2016 17:53:02] "GET /test HTTP/1.1" 500 - Traceback (most recent call last):   File
&gt; "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/flask/app.py",
&gt; line 2000, in __call__
&gt;     return self.wsgi_app(environ, start_response)   File "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/flask/app.py",
&gt; line 1992, in wsgi_app
&gt;     return response(environ, start_response)   File "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/werkzeug/wrappers.py",
&gt; line 1228, in __call__
&gt;     app_iter, status, headers = self.get_wsgi_response(environ)   File "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/werkzeug/wrappers.py",
&gt; line 1216, in get_wsgi_response
&gt;     headers = self.get_wsgi_headers(environ)   File "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/werkzeug/wrappers.py",
&gt; line 1167, in get_wsgi_headers
&gt;     for x in self.response)   File "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/werkzeug/wrappers.py",
&gt; line 1167, in &lt;genexpr&gt;
&gt;     for x in self.response)   File "/Users/michelleshieh/anaconda2/lib/python2.7/site-packages/werkzeug/_compat.py",
&gt; line 112, in to_bytes
&gt;     raise TypeError('Expected bytes') TypeError: Expected bytes
&gt; 127.0.0.1 - - [04/Oct/2016 17:53:03] "GET /favicon.ico HTTP/1.1" 404
</code></pre>

<p>The coding related to the url '/test' is:</p>

<pre><code>@app.route("/test",methods=['GET'])

    def get_local_json():
        SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
        json_url = os.path.join(SITE_ROOT, "static/data","predict.json")
        #console.log("url is all right")
        data = json.load(open(json_url))
        return app.response_class(data, content_type='application/json')
</code></pre>

<p>And the coresponding code for front-end:</p>

<pre><code>$.getJSON('/test', function(data){  
        var myData = [];
        for(var i in data){
            var item = data[i];
            var myItem = [];
            myItem.push(new Date(item.time).getTime());
            myItem.push(item.occupancy);
            myData.push(myItem);
        }
        console.log(myData);
</code></pre>

<p>Any hints are appreciated!!</p>