I have to following flask (python) server:
from flask import Flask, render_template, request, redirect, Response,jsonify
import random, json
app = Flask(__name__)
@app.route('/')
def output():
return redirect("This is a temporary implementation.")
@app.route('/model',methods = ['POST'])
def ask_model():
data = request.get_json(force=True)
print("data recieved: "+str(data))
return jsonify({'vlaue': "some response"})
if __name__ == '__main__':
# run!
#the "IP:Port" the server listens to is "localhost:5000"
app.run()
I also have a JS script running on a website called slither.io (source: https://github.com/ErmiyaEskandary/Slither.io-bot)
I want to create a learning bot and in order to do that I need to send requests between this JS script and the server, but I don't how to do it.
for example, I added to following lines to the script:
console.log("pre-post");
$.post('http://localhost:5000/model',JSON.stringify(canvasUtil.mapToMouse(window.goalCoordinates)),
function(){
console.log("entered model function.");
},'json');
console.log("post-post");
When I look at the console log only "pre-post" is printed, and my server doesn't receives any request.
Why doesn't my requests get to my local server? How do i fix this so my server will get the requests and respond to them?