“method not allowed” in a python function for flask

我与影子孤独终老i 提交于 2019-12-25 11:54:32

问题


I want to save on a .ttl file a type 'person' resource from a javascript function:

this is my sparql query:

@app.route('/registraAnnotatore/<author>+<mail>', methods=['POST'])
    def registraAnnotatore(author,mail):
    sparql = SPARQLWrapper("http://localhost:3030/data/update")
    mailto = "<mailto:"+mail+">"
    sparql.setQuery("""
        PREFIX  aop: <http://vitali.web.cs.unibo.it/AnnOtaria/person/>
        PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
        PREFIX  schema: <http://schema.org/>

    INSERT DATA
    { """+mailto+""" a foaf:Person;
      foaf:name """+author+""";
      schema:email """+mail+""".
    }

     """)
    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()
    results = results['results']['bindings']
    results = json.dumps(results)

    return results 

and this is my javascript function with the ajax call:

 function salvaRemoto(){

    $.ajax({
     method: 'GET',
     url: '/verificaAnnotatore/'+fullname+'+'+email,
     success: function(d) {
     d = JSON.parse(d);
     alert(d.length);
     if(d.length>0){
         }else{
     //registrazione nuovo utente
     $.ajax({
        method: 'POST',
        url: '/registraAnnotatore/'+fullname+'+'+email,
        success: function() {   
        alert("Utente registrato !!!");

        },
        error: function(a,b,c) {

        alert(a + ' ' + b + ' ' + c);
       }
      });
     } 

    },
    error: function(a,b,c) {
    alert(a + ' ' + b + ' ' + c);
    }
   }); 
  }

I don't know why it doesnt' work, any ideas?


回答1:


Your endpoint only accepts POST request: @app.route('/registraAnnotatore/<author>+<mail>', methods=['POST']) and in your client you are doing a GET request method: 'GET',

That's why you're getting 405 METHOD NOT ALLOWED for this endpoint ( /registraAnnotatore/<author>+<mail>).



来源:https://stackoverflow.com/questions/26236780/method-not-allowed-in-a-python-function-for-flask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!