2013-01-20 95 views
3

我试图连接到任何地方的Python上的Twitter流媒体API,但总是得到一个连接拒绝错误。PythonAnywhere拒绝Twitter API的连接

我在我的应用程序中使用Tweepy,并测试了我正在使用可在回购中找到的流式示例的连接。

这里是代码的总和式:

from tweepy.streaming import StreamListener 
from tweepy import OAuthHandler 
from tweepy import Stream 

# Go to http://dev.twitter.com and create an app. 
# The consumer key and secret will be generated for you after 
consumer_key="" 
consumer_secret="" 

# After the step above, you will be redirected to your app's page. 
# Create an access token under the the "Your access token" section 
access_token="" 
access_token_secret="" 

class StdOutListener(StreamListener): 
    """ A listener handles tweets are the received from the stream. 
    This is a basic listener that just prints received tweets to stdout. 

    """ 
    def on_data(self, data): 
     print data 
     return True 

    def on_error(self, status): 
     print status 

if __name__ == '__main__': 
    l = StdOutListener() 
    auth = OAuthHandler(consumer_key, consumer_secret) 
    auth.set_access_token(access_token, access_token_secret) 

    stream = Stream(auth, l)  
    stream.filter(track=['basketball']) 

当运行此线在bash控制台python anywhere(在已填充的过程的令牌)

12:02 ~/tweepy/examples (master)$ python streaming.py 

我得到出现以下错误:

Traceback (most recent call last): 
    File "streaming.py", line 33, in <module> 
    stream.filter(track=['basketball']) 
    File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 228, in filter 
    self._start(async) 
    File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 172, in _start 
    self._run() 
    File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 106, in _run 
    conn.connect() 
    File "/usr/local/lib/python2.7/httplib.py", line 1157, in connect 
    self.timeout, self.source_address) 
    File "/usr/local/lib/python2.7/socket.py", line 571, in create_connection 
    raise err 
socket.error: [Errno 111] Connection refused 

域.twitter.com位于pythonanywhere whithel ist虽然,所以我不明白为什么连接会被拒绝:s。

非常相同的代码就像我的Ubuntu上的魅力。

任何想法都会超过欢迎,谢谢!

回答

6

如果您使用的是免费帐户,tweepy将无法使用。它不使用环境中的代理设置。

直到主线正确使用代理服务器设置,您才有可能使用tweepy分支(http://github.com/ducu/tweepy)。

+0

嘿,thx为您的答案!我看到一个月前关闭了代理支持。我可以这样看吗? – jlengrand

+0

是的,封闭的拉不合并:s。意味着它已被拒绝。但我不知道为什么! – jlengrand

2

正如Glenn所说,目前在tweepy中没有代理支持。

由于我无法解释(而且没有记录)的原因,一个月前没有任何合并请求被关闭。

https://github.com/tweepy/tweepy/pull/152

所以显然是在github可用叉子(见格伦的答案),但我没有测试它。

由于知道我最终需要使用自己的域名,我终于在pythonanywhere上获得了付费帐户,并且一起摆脱了代理资源。