Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
446 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

you cant import in server action.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
2605
1
thg 7 25
1014
1
thg 8 25
1151
0
thg 5 25
1464
2
thg 4 25
3618