تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
25558 أدوات العرض

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
فبراير 18
4383
0
ديسمبر 17
4169
1
يوليو 25
2158
1
نوفمبر 23
11977
1
نوفمبر 22
5825