【问题标题】:Googletrans not detecting languageGoogletrans 未检测到语言
【发布时间】:2021-05-22 05:52:00
【问题描述】:

大家早上好,

我在我的代码中使用 googleTrans 来翻译句子列表。直到今天它都运行良好。现在,当我运行它时,它会将所有内容都视为英语,然后不进行任何翻译。 我尝试测试的一个经典代码:

from googletrans import Translator
translator = Translator()
results =translator.translate('हॅलो वर्ल्ड')
print(results.text)

正在打印“हॅलो वर्ल्ड”。与法语句子或其他语言相同。

translation = translator.translate("Hola Mundo")
print(f"{translation.origin} ({translation.src}) --> {translation.text} ({translation.dest})")

正在给予:“Hola Mundo (en) --> Hola Mundo (en)”

我的文本使用不同的语言,所以我无法设置一种输入语言。

知道怎么解决吗?

【问题讨论】:

    标签: python google-translate google-translator-toolkit


    【解决方案1】:

    googletrans 不使用官方 API。它使用谷歌翻译 Ajax API。 您也可以在docs 中阅读此内容。 如果您提出太多要求,尤其是一个接一个,您将被禁止。

    打开异常,你会看到你得到 HTTP 错误429 Too Many Requests:

    >>> from googletrans import Translator
    >>> translator = Translator(raise_exception=True)
    >>> print(translator.translate('हॅलो वर्ल्ड').text)
    Traceback (most recent call last):
      ...
    Exception: Unexpected status code "429" from ['translate.googleapis.com']
    

    你能做什么?不要提出太多请求或使用official API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-30
      • 2013-06-29
      • 1970-01-01
      • 2023-03-29
      • 2019-06-02
      • 2017-03-27
      • 2021-08-27
      • 2020-07-25
      相关资源
      最近更新 更多