콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
19592 화면

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.

아바타
취소
관련 게시물 답글 화면 활동
0
11월 22
2595
1
10월 22
8696
2
4월 22
10729
1
9월 20
6437
6
7월 20
11629