odoo 接口跨域请求报错

网友投稿 891 2022-10-11

odoo 接口跨域请求报错

odoo 接口跨域请求报错

浏览器显示的信息如下:​​​from origin 'has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.​​​ 参考了该博主的文章:​​https://jinxiaoliang-/V/213.html​​ 对odoo 的代码修改如下:

# 第一处 @ "/api/auth/token", methods=["GET","OPTIONS"], type="auth="none", csrf=False,cors=' save_session=False ) #第二处: if request.endpoint and 'cors' in request.endpoint.routing: self.headers.set('Access-Control-Allow-Origin', request.endpoint.routing['cors']) self.headers.set('Access-Control-Allow-Credentials', 'true') # 改 methods = 'GET, POST' if request.endpoint.routing['type'] == 'json': methods = 'POST' elif request.endpoint.routing.get('methods'): methods = ', '.join(request.endpoint.routing['methods']) self.headers.set('Access-Control-Allow-Methods', methods) # 第三处: if request.== 'OPTIONS' and request.endpoint and request.endpoint.routing.get('cors'): headers = { 'Access-Control-Max-Age': 60 * 60 * 24, 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, X-Debug-Mode' ,'Access-Control-Allow-Credentials':'true' # 改 } return Response(status=200, headers=headers)

懂得,原来世界如此简单!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:odoo 产品上的币别
下一篇:微信小程序搜索框组件:使用简单、文档注释详细、简洁美观(删除微信小程序搜索框常用小程序)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~