Skip to Content
Menu
This question has been flagged
1 Reply
139 Views

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.

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

you cant import in server action.

Related Posts Replies Views Activity
2
Aug 25
2233
1
Jul 25
770
1
Aug 25
1150
0
May 25
1262
2
Apr 25
3464