Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
42016 มุมมอง


In Odoo 11,

I have written a Web Controller to accept JSON data, as follows

class XController(http.Controller):

    @http.route('/test', type='json', auth='public', methods=['POST'], csrf=False)
    def test(self, **post):
        _logger.info('CONNECTION SUCCESSFUL!!')
        _logger.info(post)
        name = post.get('name', False)
        if not name:
            Response.status = '400 Bad Request'
        return '{"response": "OK"}'

Now when I post the data using the following Request, I get JSON Post data correctly without any issues.

headers = {'Content-Type': 'application/json'}
data = {"params" : { 'name': 'Kathy'} }
data_json = json.dumps(data) r = requests.post(url=url, data=data_json, headers=headers)

However since this request is made from an external system, the format of data is sent as follows,

data = {'name': 'Katty'}

ie without params inside data/content, Due to which, my post data is empty, how do I handle this.


Any help appreciated.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

you can directly intercept the werkzeug request object and get data from it 
like
        data = json.loads(request.httprequest.data)
you can also get use:  request.httprequest.args


อวตาร
ละทิ้ง
ผู้เขียน

Thank Goodness, you saved me...

Hello Ravi,

Can you provide some resources on how to intercet the werkzeug request in Odoo *before* this line.

https://github.com/odoo/odoo/blob/f1a5ad5f20bf1b885a3c2dc2248b8fb15b2d6565/odoo/http.py#L613

I don't have control over the callback payload, except that it is in JSON

คำตอบที่ดีที่สุด

Get it with the jsonrequest attribute

from odoo.http import request

...

data = request.jsonrequest
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Odoo mi sembra un sistema abbastanza interessante.

อวตาร
ละทิ้ง

Posso leggere le sue caratteristiche qui https://basketballstarsgame.io

คำตอบที่ดีที่สุด

Hello Kathy,

Please refer below link:

https://stackoverflow.com/questions/37111955/how-to-get-json-data-in-an-odoo-controller-using-type-json

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 17
4425
1
มิ.ย. 24
1521
0
ม.ค. 21
12953
2
ธ.ค. 19
9328
1
เม.ย. 17
12454