title: Flask "TypeError: 'NoneType' object is not iterable"
body: <p>I am following <a href="https://www.makeuseof.com/tag/python-javascript-communicate-json/" rel="nofollow noreferrer">this tutorial</a> learning how to talk to python using the javascript. I think I did the exact same thing as the tutorial said, however, I first got the error of </p>
  
  <pre><code>Unable to create process using 'flask/bin/python json_io.py'
  </code></pre>
  
  <p>Then I deleted <code>#!flask/bin/python</code> and restart the server, and got the following error.</p>
  
  <pre><code>File "json_io.py", line 22, in worker 
  for item in data:
  TypeError: 'NoneType' object is not iterable
  </code></pre>
  
  <p>My json_io.py code is as following</p>
  
  <pre><code>import sys
  
  from flask import Flask, render_template, request, redirect, Response
  import random, json
  
  app = Flask(__name__)
  
  @app.route('/')
  def output():
      # serve index template
      return render_template('index.html', name='Joe')
  
  @app.route('/receiver', methods = ['POST'])
  def worker():
      # read json + reply
      data = request.get_json()
  
      result = ''
  
  
      for item in data:
              # loop over every row
              make = str(item['make'])
              if(make == 'Porsche'):
                  result += make + ' -- That is a good manufacturer\n'
              else:
                  result += make + ' -- That is only an average manufacturer\n'
  
  
      return result
  
  if __name__ == '__main__':
      # run!
      app.run()
  </code></pre>
  
  <p>And the index.html is as follows,</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  // setup some JSON to use
  var cars = [
      { "make":"Porsche", "model":"911S" },
      { "make":"Mercedes-Benz", "model":"220SE" },
      { "make":"Jaguar","model": "Mark VII" }
  ];
  
  window.onload = function() {
      // setup the button click
      document.getElementById("theButton").onclick = function() {
          doWork()
      };
  }
  
  function doWork() {
      // ajax the JSON to the server
      $.post("receiver", JSON.stringify(cars), function(){});
  
      // stop link reloading the page
   event.preventDefault();
  }
  &lt;/script&gt;
  This will send data using AJAX to Python:&lt;br /&gt;&lt;br /&gt;
  &lt;a href="" id="theButton"&gt;Click Me&lt;/a&gt;
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>I wanted to create a jsFiddle or something. But I cannot find such a thing for python flask and website.</p>