我已经安装了 textblob,我想执行简单的翻译。
>>> text="Hello"
>>> blob=TextBlob(text)
>>> blob.translate(to="es")
问题是,我不知道在哪里指定代理身份验证。你能告诉我在哪里指定用户名、密码和代理地址,以便我可以让它工作吗?
我在我的代码中应用了这个技巧,它工作正常。
1)导入“nltk”库。
2) 在您的代码中插入这一行,根据您的需要替换用户名、密码、代理和端口:
nltk.set_proxy('http://username:password@proxy:port')
现在您的代码将如下所示:
import textblob
import nltk
from textblob import TextBlob
text="Hello"
blob=TextBlob(text)
nltk.set_proxy('http://username:password@proxy:port')
blob.translate(to="es")
print(blob.translate(to="es"))