コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
15494 ビュー

I've defined an @http.route method which receives parameters from a third party. I'm trying to access the body parameters of the request, but I can only access them if they come inside a `params` object. 

For example, I have:

@http.route(['/callback'], type='json', auth="public", csrf=False)
def handler(self, topic=None, **kw ):


and i can only access the `topic` params if in the request it was:

{ "params": {"topic": "foo"} }        


but the third party is doing the request like:

{ "topic": "foo" }        

which I'm unable to fetch. I've tried logging the contents of `**kw` but it logs {}

Thanks

アバター
破棄
著作者

Hey Jack, thanks a lot that was precisely what i needed, sorry I don't have enough karma to comment, upvote or accept the answer :(

最善の回答

Hello Bernado, 

You can use the odoo.http.request lib to grab your post data. 

An example would be:

from odoo import http
from odoo.http import request

class Test(http.Controller):
    @http.route("/test/test/", auth="public", type="json")
    def test_func(self, **kwargs):
        # POST data
        response = request.jsonrequest

Then you can get specific response data using response["topic"]. 

I hope this helps, 

Thanks, 

アバター
破棄
関連投稿 返信 ビュー 活動
4
6月 24
2019
0
2月 18
4203
2
1月 17
19068
1
11月 22
2602
2
4月 16
4215