title: API serving up old responses in flask
body: <p>I'm calling a Flask api, run by gunicorn and which is served out by nginx all on a linux box viretal env</p>
  
  <p>When I use curl or postman to test I get 1 of 4 responses randomly each time I run - but mostly response 2 below</p>
  
  <p>Here's my flask api py file. I'm new to this so excuse any errors:</p>
  
  <pre><code>app = Flask(__name__)
  now = datetime.now()
  timestamp=str(now.strftime("%Y-%m-%d %H:%M"))
  
  # assignes route for POSTING JSON requests
  @app.route('/api/v1.0/my-api', methods=['POST'])
  #@requires_auth
  def runscope():
      if request.method == 'POST':
          in_json = request.json
      in_json["api_datetime"] = timestamp
      json_to_file(in_json)
          return timestamp + "New msg log file success!" 
  
  
  # assigns route for the default GET request
  @app.route('/')
  def index():
      return 'test on the index'  
  
  
  if __name__ == "__main__":
      app.debug = True
      application.run()
  
  # function to drop request data to file
  def json_to_file(runscope_json):
      with open('data/data.json', 'a') as outfile:
              json.dump(runscope_json, outfile, indent=2)
  </code></pre>
  
  <p>So when I run the test below several times in a row</p>
  
  <pre><code>curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:8000/api/v1.0/my-api
  </code></pre>
  
  <p>I get either
  1. Response: "New msg log file success!" with the json getting to the file i specified</p>
  
  <p>OR</p>
  
  <ol start="2">
  <li>Response: "log file success!" which was in an old version of the python code above! The data gets to the file but without the timestamp as the old code didn't have it</li>
  </ol>
  
  <p>OR</p>
  
  <ol start="3">
  <li>"Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."</li>
  </ol>
  
  <p>OR</p>
  
  <ol start="4">
  <li><code>{ "message": "Authenticate." }</code> which is a response I had in another OLD version of the code!</li>
  </ol>
  
  <p>Note: I  do a "<code>gunicorn my-api:app</code>" and a <code>nginx</code> restart if I changed the code, making sure to manually delete the <code>.pyc</code> file first</p>
  
  <p>Can anyone help out? Wheres it getting the old code responses from? Why is it intermittent, giving me the expected new code response only sometimes?</p>