在代理后面使用 Tweepy API [英] Using Tweepy API behind proxy

查看:86
本文介绍了在代理后面使用 Tweepy API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Tweepy,一个用于 Twitter 的 Python 包装器.我正在用 Python 编写一个小型 GUI 应用程序,用于更新我的 Twitter 帐户.

I have a using Tweepy, a python wrapper for Twitter.I am writing a small GUI application in Python which updates my twitter account.

目前,我只是在测试我是否可以连接到 Twitter,因此使用了 test() 调用.我支持 Squid 代理服务器.我应该对代码片段进行哪些更改才能完成工作.

Currently, I am just testing if the I can get connected to Twitter, hence used test() call. I am behind Squid Proxy server.What changes should I make to snippet so that I should get my work done.

在 bash shell 中设置 http_proxy 对我没有帮助.

Setting http_proxy in bash shell did not help me.

def printTweet(self):
    #extract tweet string
    tweet_str = str(self.ui.tweet_txt.toPlainText()) ;
    #tweet string extracted.
    self.ui.tweet_txt.clear()  ;

    self.tweet_on_twitter(str);

def tweet_on_twitter(self,my_tweet) :
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET);
    auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) ;
    api = tweepy.API(auth) ;

    if api.test() :
        print 'Test successful' ;
    else :
        print 'Test unsuccessful';

推荐答案

我想你应该改为设置 'https_proxy'.

I guess you should set 'https_proxy' instead.

在我的 linux 上,我使用这个:

On my linux, I use this:

> export HTTPS_PROXY="http://xxxx:8888"

在运行我的 Tweepy 脚本之前.

before running my Tweepy script.

Tweep 使用 'requests' 包发送请求,阅读 http://docs.python-requests.org/en/master/user/advanced/#proxies 了解更多.

Tweep uses 'requests' package for sending request, read http://docs.python-requests.org/en/master/user/advanced/#proxies for more.

这篇关于在代理后面使用 Tweepy API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆