So I want to send an array to a python script using flask.
Here's my relevant javascript:
var blacklist = [1];
function getSents() {
$.ajax({
type: "POST",
url: "script.py",
data: {'blacklist':blacklist},
dataType: 'json',
success: function(response) {
// do something
},
error: function (xhr, status, error) {
console.log(error);
}
});
}
And in flask, I have tried every Attribute of request that I found. When printed, it always gives an empty bytes string.
If I use
json.loads(request.data)
It raises an error because request.data is empty.
Relevant python code:
from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify
application = Flask(__name__)
@application.route('/', methods=['GET', 'POST'])
def something():
blacklist = request.get_data()
# do something
if __name__ == '__main__':
application.run(debug=True)