python bottle搭建http服务post请求时出现405状态码怎么回事?,python405,网上有方案说改核心代码c
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')
编橙之家文章,
相关内容
- pyspider默认保存到sqlite数据库的时候是什么编码》,p
- python脚本更新文档中的内容相关问题,python相关问题
- fabric怎么才能操作host设置别名的?,fabrichost设置别名
- 同个镜像文件iso能被多个虚拟机使用的吗,镜像iso多个
- django testcase 临时数据库表中无数据的解决,djangotestc
- python 2.x中pyinstaller 如何打包配置文件?,2.xpyinstaller,主
- tornado框架异步请求如何实现模拟登录?,tornado框架,之前
- python2.x版本 导入urllib3的异常“cannot import name LifoQueue”
- Scrapy框架怎么直接读数据库中的URL地址进行抓取呢?,
- django框架EmailMessage来发送邮件会有乱码,怎么解决?,
评论关闭