Odoo Help

0

How to get data in Odoo from outside and give a response?

By
Juan Formoso
on 3/11/16, 5:42 AM 1,169 views

I am trying to get some data in Odoo from outside, work with that data, and give a response.

So I did a controller:

import openerp.http as http
import logging
_logger = logging.getLogger(__name__)

class Controller(http.Controller):
     @http.route('/test/result', type='http', auth='none', website=False)
     def index(self, **args):
          _logger.info('HOLA')
          return '{"response": "OK"}'

With this code, if I go to http://localhost:8069/test/result, I get {"response": "OK"}, which is what I want.

The problem is that the request is not going to be typing the controller URL on a browser, but from the code of a website.

So I am trying to connect to the controller from the Python console:

>>> import requests
>>> requests.get('http://localhost:8069/test/result', data='{"x": "test",}')

What I always get is:

>>> <Response [404]>

Instead of '{"response": "OK"}'.

Please, help!

1
Motez
On 3/11/16, 9:30 AM

You are getting the 404 error because odoo does'nt know which database to use if you use your browser in private mode you'll also get the 404 error same as in your python code. to solve this you need to use just one database. If you are in a developement environnement you can use --db-filter option

 

Thank you @Motez. That is the problem.

Juan Formoso
on 3/14/16, 6:08 AM

However, auth='none' means there is no database access, so it should still work with many databases. You can take a look at what handles the /web/database/selector address in addons/web/controlles/main.py. This address works, but shows no apparent difference with OP's code.

Jérôme Thériault
on 3/15/17, 10:16 AM
0
Jérôme Thériault
On 3/15/17, 11:11 AM

Odoo usually needs a database so it knows what modules are used and loaded. There are however server wide modules that are loaded even without any database. By default, I think they are web and web_kanban.

These modules are configurable in openerp.conf like so (I'm not sure about web_kanban, but web definately has to be there):

server_wide_modules = web,web_kanban,my_module

Then, if you really need access to a database, because the request of a auth='none' method has no env, the name and uid has to be either hard coded or passed to the controller via the request, and you can follow this question's accepted answer to create a new environment to work with:

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-get-a-new-cursor-on-new-api-on-thread-63441

P.S.: There was a bug where Odoo did not read the server_wide_modules variable in the config file and we had to use the --load command line argument. The config file works fine here with Odoo 8.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 3/11/16, 5:42 AM
Seen: 1169 times
Last updated: 3/15/17, 11:11 AM