Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
React Native llama a la API de Odoo a través de Axios luchando con CORS

Estoy usando React Native e intento llamar a las API de Odoo usando Axios.

Así es como llamo con éxito a la authenticate en mi instancia local de Odoo.

 const authenticate = await axios.post('http://localhost:8069/web/session/authenticate', { params: { db: 'db', login: 'odoo', password: 'odoo', } } );

Ahora que obtuve el resultado de Odoo. Quiero llamar a métodos y consultar algunos registros.

Entonces, traté de obtener algunos registros de DataSet search_read primero.

Esto es lo que probé.

 const search_read = await axios.post('http://localhost:8069/web/dataset/search_read', { params: { model: 'stock.picking', fields: ['id','name'], } } );

Me dio este error.

El acceso a XMLHttpRequest en 'http://localhost:8069/web/dataset/search_read' desde el origen 'http://localhost:19006' ha sido bloqueado por la política de CORS: no está presente el encabezado 'Access-Control-Allow-Origin' sobre el recurso solicitado.

Aunque ya heredé y personalicé ambos @http.route para permitir CORS en el lado de Odoo.

 from odoo.addons.web.controllers.main import Session, DataSet from odoo import http class SessionInherit(Session): @http.route('/web/session/authenticate', type='json', auth="none", cors='*') def authenticate(self, db, login, password, base_location=None): return super(SessionInherit, self).authenticate(db, login, password, base_location) class DataSetInherit(DataSet): @http.route('/web/dataset/search_read', type='json', auth="user", cors='*') def search_read(self, model, fields=False, offset=0, limit=False, domain=None, sort=None): return super(DataSetInherit, self).search_read(model, fields, offset, limit, domain, sort)

¿Cómo soluciono este problema?

Nota : la solicitud de autenticación también tuvo un problema de CORS antes de personalizar el método de authenticate para permitirlo. Una vez que lo hice, funciona bien. Sin embargo, cuando hago lo mismo para search_read , todavía me da un error CORS.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!