google app engine: 405 method not allowed

2019-06-22 11:06发布

What are the causes for the the error NetworkError: 405 Method Not Allowed

I was using a web service and all of a sudden it started returning that error. its not maintained so it will not get fixed. I am curious if i can do something about this.

The offending web service url is: http://jsonpdb.appspot.com/add

3条回答
老娘就宠你
2楼-- · 2019-06-22 11:33

The method (GET/POST/HEAD etc) you're trying to use on that URL is not supported by the app. Are you sure the API expects you to use the method you're using on that URL?

查看更多
【Aperson】
3楼-- · 2019-06-22 11:42

Most common cause is using the wrong 'get' vs 'post' for the response. Verify what's being sent and that the correct method appears in the your handler.

class MainHander(webapp.RequestHandler):
    def get(self):
        ...
    def post(self):
        ....
    def delete(self):
        ....

Another common issue is having the main dispatch section parse urls, but then not supply them in the get/post/delete

def main():
    application = webapp.WSGIApplication(
        [   (r'/upload/([^/]+)?/?', UploadFileHandler),

The regex there has () in it... that's a parameter in the url path like: /upload/filename

class UploadFileHandler(webapp.RequestHandler):
    def post(self, filename):
        ...

Supplying a link to code would be helpful.

查看更多
该账号已被封号
4楼-- · 2019-06-22 11:47

I know this is an old thread but I did not find a satisfactory answer to the question for my own needs. Especially if you're handling an AJAX response, you may want to explicitly allow OPTIONS requests by checking for them in the dispatch of your custom WebApp2 handler:

class MyHandler(webapp2.RequestHandler):
    def __init__(self, request, response):
        self.initialize(request, response)

    #The dispatch is overwritten so we can respond to OPTIONS
    def dispatch(self):
        self.response.headers.add_header("Access-Control-Allow-Origin", "*")
        if self.request.method.upper() == 'OPTIONS':
            self.response.status = 204
            self.response.write('')
        else:
            super(MyHandler, self).dispatch();
查看更多
登录 后发表回答