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

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!

아바타
취소
베스트 답변

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.

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.

베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
0
2월 18
4478
0
12월 17
4236
1
7월 25
2304
1
11월 23
12062
1
11월 22
5895