From 5da6d0f9c9e0061bacae033a97d473f9125362ac Mon Sep 17 00:00:00 2001 From: Ivan Office Date: Wed, 27 Sep 2023 07:24:08 +0800 Subject: [PATCH] fix email --- app_common/__manifest__.py | 2 +- app_common/models/base.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app_common/__manifest__.py b/app_common/__manifest__.py index 1be0a196..5339258d 100644 --- a/app_common/__manifest__.py +++ b/app_common/__manifest__.py @@ -39,7 +39,7 @@ { 'name': "odooai Odooapp Common Func", - 'version': '16.23.08.17', + 'version': '16.23.09.27', 'author': 'odooai.cn', 'category': 'Base', 'website': 'https://www.odooai.cn', diff --git a/app_common/models/base.py b/app_common/models/base.py index 000e850e..70472217 100644 --- a/app_common/models/base.py +++ b/app_common/models/base.py @@ -101,19 +101,22 @@ class Base(models.AbstractModel): @api.model def get_image_from_url(self, url): - if not url: - return None - try: - response = requests.get(url) # 将这个图片保存在内存 - except Exception as e: - return None # 返回这个图片的base64编码 - return base64.b64encode(BytesIO(response.content).read()) + return get_image_from_url(url) def get_ua_type(self): return get_ua_type() - +def get_image_from_url(url): + if not url: + return None + try: + response = requests.get(url, timeout=5) + except Exception as e: + return None + # 返回这个图片的base64编码 + return base64.b64encode(BytesIO(response.content).read()) + def get_ua_type(): ua = request.httprequest.headers.get('User-Agent') # 临时用 agent 处理,后续要前端中正确处理或者都从后台来