mardi 24 novembre 2015

Flask 405 POST Method Not Allowed

I'm developing a Web app; I got an error in browser console, after adding a new Python/Flask method that I call via Ajax:

"POST 405 (METHOD NOT ALLOWED)"

I've found many similar questions here, but no answer worked:

  • I specified both GET and POST methods for the route: methods=['GET','POST']
  • I restarted apache
  • I set dataType to "jsonp"

Several Python/Flask functions in the same file are already working in the same way, with no problem. Maybe Flask should be reloaded? configured with the new route?

Also, everything worked fine with my local server on my machine. It's only now that I'm porting the code to the hosting server that I got this issue.

My JS

function launchStreaming(jsonPath){
    var data = {};
    data.file = jsonPath;

    $.ajax({
        type: 'POST',
        url: "/launchStream",
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function(data) {
            stringDebug('streaming Success!');
        },
        error: function(e) {
            stringDebug(e);
            alert ("Problem during streaming, please refresh and retry");
        }
     });

My Python

@app.route('/launchStream', methods=['POST'])
def launchStream():
    if request.method == 'POST':
        json_datas = request.json
        # do streaming...

        return json.dumps({'success':True}), 200, {'ContentType':'application/json'}

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire