コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
435 ビュー

This is the problem I've encountered. In Odoo Online when you define a requests.post() in a server action it works just fine. But when you have Odoo On-Premise it does not work and gives requests is not defined. And this problems show in Odoo17 as well as Odoo18.

I am trying to send a request but it does not let me to.

アバター
破棄
最善の回答

Hi,

Import requests in your Server Action

import requests


Then your request will work:

import requests


response = requests.post(

    ' example.com ")

payload = json.dumps({

    "key": "value"

})

headers = {

    'Content-Type': 'application/json'

}

conn.request("POST", "/api/endpoint", payload, headers)

res = conn.getresponse()

data = res.read()


if res.status != 200:

    raise UserError(f"Request failed: {data.decode('utf-8')}")


I hope it is usefull.

アバター
破棄
著作者

you cant import in server action.

関連投稿 返信 ビュー 活動
2
8月 25
2598
1
7月 25
1006
1
8月 25
1151
0
5月 25
1458
2
4月 25
3610