From c6063942c28153e64123c8b231b5fe48e649f14b Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Thu, 11 Apr 2024 12:37:08 +0300 Subject: [PATCH] fixed translator error --- akarpov/music/services/db.py | 6 +++++- akarpov/music/services/info.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/akarpov/music/services/db.py b/akarpov/music/services/db.py index 6899249..4cd3ba1 100644 --- a/akarpov/music/services/db.py +++ b/akarpov/music/services/db.py @@ -2,7 +2,11 @@ import re import requests -from deep_translator import GoogleTranslator + +try: + from deep_translator import GoogleTranslator # TODO: move to another service +except requests.exceptions.JSONDecodeError: + print("Failed to initialize GoogleTranslator due to external API issues.") from django.core.files import File from django.db import transaction from django.utils.text import slugify diff --git a/akarpov/music/services/info.py b/akarpov/music/services/info.py index 8f2b94b..9177b00 100644 --- a/akarpov/music/services/info.py +++ b/akarpov/music/services/info.py @@ -3,7 +3,11 @@ import requests import spotipy -from deep_translator import GoogleTranslator + +try: + from deep_translator import GoogleTranslator +except requests.exceptions.JSONDecodeError: + print("Failed to initialize GoogleTranslator due to external API issues.") from django.conf import settings from django.core.files import File from django.db import transaction