Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
558 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 25
2768
1
ก.ค. 25
1117
1
ส.ค. 25
1152
0
พ.ค. 25
1533
2
เม.ย. 25
3735