python bottle搭建http服务post请求时出现405状态码怎么回事?,python405,网上有方案说改核心代码c


网上有方案说改核心代码

class HTTPResponse(Response, BottleException):    def __init__(self, body='', status=None, headers=None, **more_headers):        super(HTTPResponse, self).__init__(body, status, headers, **more_headers)     def apply(self, response):        response._status_code = self._status_code        response._status_line = self._status_line        if self._headers:            if response._headers:                response._headers.update(self._headers)            else:                response._headers = self._headers         response._cookies = self._cookies        response.body = self.body

或者

#!/usr/bin/python  # -*- conding:utf-8 -*-    from bottle import *    #decorator  def allow_cross_domain(fn):      def _enable_cors(*args, **kwargs):          #set cross headers          response.headers['Access-Control-Allow-Origin'] = '*'          response.headers['Access-Control-Allow-Methods'] = 'GET,POST,PUT,OPTIONS'          allow_headers = 'Referer, Accept, Origin, User-Agent'          response.headers['Access-Control-Allow-Headers'] = allow_headers               if bottle.request.method != 'OPTIONS':              # actual request; reply with the actual response              return fn(*args, **kwargs)          return _enable_cors        @route('/helloworld/:yourwords', methods=['GET', 'POST'])  @allow_cross_domain                                              #在此处加上定义的函数  def hello(yourwords):      return 'hello world. ' + yourwords    run(host='0.0.0.0', port=8080)  

我发现都不行,get请求可以的,post请求就405 Method Not Allowed

我的代码

from bottle import route, run, request, response@route('/color/a')def colora():    print(request.forms.get('words'))    print('xxxx')    return '{"name":"test"}'run(host='0.0.0.0', port=50001, debug=True)

from bottle import get, post, request # or route
@post ('/login') # or @route('/login', method='POST')

编橙之家文章,

评论关闭