I'm calling a Flask api, run by gunicorn and which is served out by nginx all on a linux box viretal env
When I use curl or postman to test I get 1 of 4 responses randomly each time I run - but mostly response 2 below
Here's my flask api py file. I'm new to this so excuse any errors:
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)
So when I run the test below several times in a row
curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:8000/api/v1.0/my-api
I get either 1. Response: "New msg log file success!" with the json getting to the file i specified
OR
- 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
OR
- "Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
OR
{ "message": "Authenticate." }
which is a response I had in another OLD version of the code!
Note: I do a "gunicorn my-api:app
" and a nginx
restart if I changed the code, making sure to manually delete the .pyc
file first
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?