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

Currently Trying to call a odoo controller which return json data as per my exception .

@http.route('/web/update_order_webhook', type='http', csrf=False, auth="public")
def update_order_webhook(self, **kwargs):
    return Response(json.dumps({"yes":"i am json"}),content_type='application/json;charset=utf-8',status=200)

when i tried to call this end point

import requests

url = "http://159.89.197.219:8069/web/update_order_webhook"

headers = {
    'content-type': "application/json"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

I get Request Body

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Invalid JSON data: ''</p>

And Request Header at my calling end point

content-length →137
content-type →text/html
date →Thu, 11 Jan 2018 20:32:53 GMT
server →Werkzeug/0.13 Python/3.5.2

that clearly mean that i am not getting json response data from my odoo endpoint . Please correct me if i am wrong at any point. Thanks for your time

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

Use type='json' instead of type='http' in decorator parameters


To get JSON data I use:
curl -i -X POST -H "Content-Type: application/json" -d "{}" localhost:8069/edi/get_json_orders

or python
url = "http://localhost:8069/edi/get_json_orders"
headers = {'content-type': 'application/json' }
payload = {}
response = requests.post(url, headers=headers, data=json.dumps(payload))


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

n the controllers decorator `@route` you define a type='http' and request with header "application/json".

Odoo dispatcher will create a JsonRequest Object and expect to receive a json object along with the request.

Change header's 'content-type' to 'message/http' and it should be fine.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
พ.ย. 22
2571
1
ต.ค. 22
8657
2
เม.ย. 22
10686
1
ก.ย. 20
6397
6
ก.ค. 20
11577