繁体   English   中英

不允许使用Flask 405 POST方法

[英]Flask 405 POST Method Not Allowed

我正在开发一个Web应用程序; 添加通过Ajax调用的新Python / Flask方法后,浏览器控制台出现错误:

“ POST 405(不允许使用方法)”

我在这里找到了许多类似的问题,但没有答案可以解决:

  • 我为路由指定了GET和POST方法: methods=['GET','POST']
  • 我重新启动了Apache
  • 我将dataType设置为“ jsonp”

同一文件中的多个Python / Flask函数已经以相同的方式工作,没有问题。 也许应该重新装瓶? 配置了新路线?

而且,一切都可以在我的计算机上的本地服务器上正常运行。 直到现在,我才将代码移植到托管服务器上,从而解决了这个问题。

我的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");
        }
     });

我的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'}

提前致谢

检查生产中是否有任何uwsgi服务(例如ps -aux ,尝试找到诸如uwsgi --ini myproject.ini之类的行 )。 如果您找到uwsgi,请重新启动它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM