I tried different ways of doing that, but they didn't work.
First I tried this way:
import openerp.http as http
from openerp.http import Response
class ResPartnerController(http.Controller):
@http.route('/odoo/create_partner', type='json', auth='none')
def index(self, **kwargs):
Response.status = '400'
return "Result message"
I get the right status and the message in the client. But I get this strange warning if I do any action on the Odoo interface
Is there a way to avoid this message?
I tried this both ways as well:
data = {'result': 'RESULT message'}
json_data = json.dumps(data, encoding='utf-8')
headers = [('Content-Type', '{}; charset=utf-8'.format('application/json'))]
mimetype = 'application/json'
res = Response(
response=json_data,
status=status,
headers=headers,
mimetype=mimetype,
)
return res
msg = u'Response 200 badly built, falling back to a simple 200 OK response'
res = Response(msg, status=200)
return res
But I always get this error as answer in the client:
TypeError: <Response 9 bytes [400 BAD REQUEST]> is not JSON serializable\n", "message": "<Response 9 bytes [400 BAD REQUEST]> is not JSON serializable"
So, is there a clean way of answer a simple message with the status of the response?
It is important for me to send the status of the response as well
If I simply respond a message everything works fine, but how to change the status without strange behaviours?
By the way, I use this script to do the calls
# -*- coding: utf-8 -*-
import requests
import json
url = 'http://localhost:8069/odoo/create_partner'
headers = {'Content-Type': 'application/json'}
data_res_partner = {
'params': {
'name': 'Example',
'email': 'jamon@test.com',
}
}
data_json = json.dumps(data_res_partner)
response = requests.post(url=url, data=data_json, headers=headers)
print(response.status_code)
print(response.content)
Update
Finally @Phillip Stack told me to do this with XML-RPC, so I wrote this other question in order to clarify my doubts.