Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4092 Представления
# I have this request that i send in python.
import requests headers = { 'Content-Type': 'application/json', 'api_key': '1233445677676' # api_key is fake } data = '{"params": {"name":"Opportunity using auth_key","type":"opportunity"}}' response = requests.post('https://ex-test.odoo.com/leads', headers=headers, data=data) print(response.json())

# This is odoo version 15 controller code
import json from werkzeug.exceptions import BadRequest import logging from odoo import http from odoo import models from odoo.http import request _logger = logging.getLogger(__name__) class IrHttp(models.AbstractModel): _inherit = "ir.http" @classmethod def _auth_method_api_key(cls): api_key = request.httprequest.headers.get("api_key") if not api_key: raise BadRequest("Authorization header with API key missing") user_id = request.env["res.users.apikeys"]._check_credentials( scope="rpc", key=api_key ) if not user_id: raise BadRequest("API key invalid") request.uid = user_id class CRMc(http.Controller): @http.route('/leads', type='json', auth="api_key", methods=['POST']) def api_authenticate(self, **kw): if request.uid: rec_id = request.env['crm.lead'].create({ 'create_uid': request.uid, 'type': http.request.params.get('type'), 'name': http.request.params.get('name'), }) return json.dumps(rec_id.id)

I have sent request using postman and the python code i provided.But when i send request i do not get header on the server side and receive error like Authorization header with API key missing.

I am not getting my api_key on the server side.

I have tried in local environment. In local, it works fine. But when i have tried in odoo.sh it is not receiving header.

If anyone has any idea on this please help.

Аватар
Отменить

Please check the Odoo version running on Odoo.sh, may be different from the version running in the local environment.

Автор

Odoo.sh has V15

did you get any solution ?

Лучший ответ

Dear

replace _ by - like this api-key instead of api_key. it will work

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
дек. 23
1957
1
июн. 22
2766
1
авг. 25
266
3
июл. 24
6083
1
дек. 23
2583