Explorar el Código

fix: env vars type error (#1127)

master
lanvent hace 1 año
padre
commit
4c5e8850aa
Se han modificado 1 ficheros con 3 adiciones y 1 borrados
  1. +3
    -1
      translate/baidu/baidu_translate.py

+ 3
- 1
translate/baidu/baidu_translate.py Ver fichero

@@ -17,13 +17,15 @@ class BaiduTranslator(Translator):
self.url = endpoint + path
self.appid = conf().get("baidu_translate_app_id")
self.appkey = conf().get("baidu_translate_app_key")
if not self.appid or not self.appkey:
raise Exception("baidu translate appid or appkey not set")

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



Cargando…
Cancelar
Guardar