目前正在尝试调用一个 odoo 控制器,该控制器根据我的异常返回 json 数据。
@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)
当我试图调用这个端点时
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)
我得到请求正文
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Invalid JSON data: ''</p>
并在我的呼叫端点请求标头
content-length →137
content-type →text/html
date →Thu, 11 Jan 2018 20:32:53 GMT
server →Werkzeug/0.13 Python/3.5.2
这显然意味着我没有从我的 odoo 端点获取 json 响应数据。根据最后一个答案,我更新了我的代码
@http.route('/web/update_order_webhook', type='json', auth="public", website=True)
def update_order_webhook(self, **kwargs):
return json.dumps({"yes":"i am json"})
但是现在我在调用端点时遇到了新错误
Bad Request
<function Binary.update_order_webhook at 0x7efd82ac8510>, /web/update_order_webhook: Function declared as capable of handling request of type 'json' but called with a request of type 'http'