跳至內容
選單
此問題已被標幟
1 回覆
1081 瀏覽次數

I am using the following code to get user ip information to record activity history, but the received ip is the ip of the active server, my Odoo server is deployed on ubuntu server 22.04


This is my code:

def _get_info_active(self):
"""
:return: ip_address, location, device_name
"""
try:
client_ip = request.httprequest.environ['REMOTE_ADDR']
location_info = {}
try:
response = requests.get(f'https://ipinfo.io/{client_ip}/json')
location_info = response.json()
except requests.RequestException:
location_info = {"error": "Could not retrieve location info"}

user_agent = request.httprequest.user_agent.string
return client_ip, f"{location_info.get('city')}, {location_info.get('region')}, {location_info.get('country')}", user_agent

except Exception as e:
raise UserError(str(e))
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
3月 15
4517
7
2月 24
12249
0
11月 17
4047
1
5月 25
1089
0
11月 24
1274