Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
385 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

you cant import in server action.

Post correlati Risposte Visualizzazioni Attività
2
ago 25
2572
1
lug 25
980
1
ago 25
1151
0
mag 25
1427
2
apr 25
3605