Skip to content

Commit 4c5e885

Browse files
committed
fix: env vars type error (zhayujie#1127)
1 parent 165182c commit 4c5e885

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

translate/baidu/baidu_translate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ def __init__(self) -> None:
1717
self.url = endpoint + path
1818
self.appid = conf().get("baidu_translate_app_id")
1919
self.appkey = conf().get("baidu_translate_app_key")
20+
if not self.appid or not self.appkey:
21+
raise Exception("baidu translate appid or appkey not set")
2022

2123
# For list of language codes, please refer to `https://api.fanyi.baidu.com/doc/21`, need to convert to ISO 639-1 codes
2224
def translate(self, query: str, from_lang: str = "", to_lang: str = "en") -> str:
2325
if not from_lang:
2426
from_lang = "auto" # baidu suppport auto detect
2527
salt = random.randint(32768, 65536)
26-
sign = self.make_md5(self.appid + query + str(salt) + self.appkey)
28+
sign = self.make_md5("{}{}{}{}".format(self.appid, query, salt, self.appkey))
2729
headers = {"Content-Type": "application/x-www-form-urlencoded"}
2830
payload = {"appid": self.appid, "q": query, "from": from_lang, "to": to_lang, "salt": salt, "sign": sign}
2931

0 commit comments

Comments
 (0)