콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
11299 화면

Hey!

I've read this post: https://www.odoo.com/es_ES/forum/ayuda-1/post-to-external-url-from-server-action-99309 and asked for some help there but got none, also I cannot continue the conversation there since i don't have enough karma. My question is how can i do an external HTTP request on a Server Action?, I've tried with Python Requests like:

```
requests.get("http://example.com")
```

but i get:

ValueError: <class 'NameError'>: "name 'requests' is not defined" while evaluating

I've tried installing urllib3 with: `sudo pip install urllib3` but looks like it is already installed:

`Requirement already satisfied: urllib3 in /opt/bitnami/python/lib/python3.7/site-packages/urllib3-1.22-py3.7.egg`

thanks!

아바타
취소
베스트 답변

Hello,

In server actions I don't believe this is possible, when using requests you need to import the requests python library.

I have found the best way to achieve what you need is to create a custom module with a model that extends the model you want the server action to run on and define a function. Eg Def call_endpoint(self):

Then you can call this function in the server action you call this function using record.call_endpoint() and you request call will be in this function.

If you need further help, let me know,

Thanks,

아바타
취소
베스트 답변

Hello,

I have the same problem, can someone help me please?

Thanks 

아바타
취소
베스트 답변

The only Python libraries you can access in a Server Action are: datetime, dateutil, time, timezone.


See https://www.odoo.com/documentation/14.0/reference/actions.html#evaluation-context - to use other libraries, write a module that creates an action that you can then call, review the base_geolocalize module for an idea (this module leverages Open StreetMap)

아바타
취소
작성자 베스트 답변

Thanks @Jack Dane, i did what you suggested and it worked!

아바타
취소
관련 게시물 답글 화면 활동
3
8월 20
10855
0
7월 17
3485
2
8월 20
8387
2
8월 24
1713
0
1월 25
1645