"HTTPError: HTTP Error 404: Not Found" while using translation function in TextBlob

"HTTPError: HTTP Error 404: Not Found" while using translation function in TextBlob

当我尝试在 jupyter notebook 的 TextBlob 库中使用 t运行slate 函数时,我得到:

HTTPError: HTTP Error 404: Not Found

我把我的代码和报错信息的截图贴在这里供参考。这段代码在 5-6 天前运行良好,当时我第一次 运行 完全相同的代码,但之后每当我 运行 这段代码时,它都会给我相同的错误消息。自从过去 4-5 天以来,我一直在尝试 运行 此代码,但它再也没有用过。

我的代码:

from textblob import TextBlob

en_blob = TextBlob('Simplilearn is one of the world’s leading certification training providers.')

en_blob.translate(to='es')  

我是 Whosebug 的新手,在这个平台上提出了我的第一个问题,所以如果我的问题没有遵循这个平台的规则,请原谅我。

Textblob 库在后端使用 Google API 翻译功能。 Google 最近对其 API 进行了一些更改。由于这个原因,TextBlob 的翻译功能已停止工作。我注意到,如下所述,通过对 translate.py 文件(在所有 TextBlob 文件所在的文件夹中)进行一些小改动,我们可以消除此错误:

原代码:

url = "http://translate.google.com/translate_a/t?client=webapp&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"

将 translate.py 中的上述代码更改为以下内容:

url = "http://translate.google.com/translate_a/t?client=te&format=html&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"

我刚刚试过了。第一次对我不起作用。

我重新启动了 Anaconda Prompt,重新启动了 IPython。并重新 运行 我的代码片段,问题在修复后消失了。我用的是Windows10,我没有用虚拟环境,改的两个文件是:

C:\Users\behai\anaconda3\pkgs\textblob-0.15.3-py_0\site-packages\textblob\translate.py
C:\Users\behai\anaconda3\Lib\site-packages\textblob\translate.py

而且我还发现我必须为换行符做制表符缩进。

添加于 2021 年 2 月 1 日:

我什么都没做。我应用了 Manish 先生的建议(上面的绿色勾号)。我在 Anaconda 环境中遇到了这个 404 问题。应用上述更改后,我刚刚重新启动了“Anaconda Prompt (anaconda3)”,它成功了。

这是上面建议的更改,在:

C:\Users\behai\anaconda3\Lib\site-packages\textblob\translate.py
    # url = "http://translate.google.com/translate_a/t?client=webapp&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"
    url = "http://translate.google.com/translate_a/t?client=te&format=html&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"

以下文件自动更新:

C:\Users\behai\anaconda3\pkgs\textblob-0.15.3-py_0\site-packages\textblob\translate.py

固定在https://github.com/sloria/TextBlob/pull/398

您应该使用带有该修复程序的标记版本。

# requirements/txt
textblob @ git+https://github.com/sloria/TextBlob@0.17.1#=textBlob