【问题标题】:Setting proxy for textblob为 textblob 设置代理
【发布时间】:2015-12-02 06:21:34
【问题描述】:

我已经安装了 textblob,我想进行简单的翻译。

>>> text="Hello"
>>> blob=TextBlob(text)
>>> blob.translate(to="es")

问题是,我不知道在哪里指定代理身份验证。你能告诉我在哪里指定用户名、密码和代理地址,以便我可以使用它吗?

【问题讨论】:

    标签: python textblob


    【解决方案1】:

    我在我的代码中应用了这个技巧,它运行良好。

    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"))
    

    【讨论】:

    • 成功了吗?我试过这段代码无济于事。我收到此错误: urllib.error.HTTPError: HTTP 错误 403: URLBlocked-category_restriction
    • 它也对我有用!有时这个世界非常简单!
    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 2011-06-11
    • 2016-04-07
    • 2013-01-25
    • 2012-06-28
    相关资源
    最近更新 更多