Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
fix error:GoogleTranslateWebTranslator->'NoneType' object is not subs…
Browse files Browse the repository at this point in the history
…criptable:
  • Loading branch information
versun committed Apr 2, 2024
1 parent c916943 commit 4909264
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion django_text_translator/models/google_translate_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def translate(self, text:str, target_language:str) -> dict:
}
resp = httpx.get(self.base_url, params=params, timeout=10, proxy=self.proxy)
resp.raise_for_status()
translated_text = resp.json()[0][0][0]
resp_json = resp.json()
if resp_json:
translated_text = resp_json[0][0][0]
else:
logging.error("GoogleTranslateWebTranslator->Invalid response: %s", resp.text)
except Exception as e:
logging.error("GoogleTranslateWebTranslator->%s: %s", e, text)
finally:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages = ["./"]

[project]
name = "django-text-translator"
version = "2024.4.2"
version = "2024.4.2.1"
authors = [
{ name="Versun", email="[email protected]" },
]
Expand Down

0 comments on commit 4909264

Please sign in to comment.