【问题标题】:Connection refused to Twitter API on PythonAnywherePythonAnywhere 上的连接拒绝 Twitter API
【发布时间】:2013-01-03 16:01:29
【问题描述】:

我正在尝试在任何地方连接到 Python 上的 twitter 流 API,但总是收到连接被拒绝错误。

我在我的应用程序中使用Tweepy,为了测试连接,我使用了可以在 repo 中找到的流式传输示例。

这里是代码的总结:

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'])

当我在 python anywhere 的 bash 控制台中运行此行时(当然是在填充了令牌之后)

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 whithelist 中,所以我不明白为什么连接会被拒绝:s。

同样的代码在我的 Ubuntu 上就像一个魅力。

欢迎任何想法,谢谢!

【问题讨论】:

    标签: python twitter streaming twitter-oauth pythonanywhere


    【解决方案1】:

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

    在主线正确使用代理设置之前,您可以使用 tweepy 的一个分支 (http://github.com/ducu/tweepy)。

    【讨论】:

    • 嘿,谢谢你的回答!我看到一个月前关闭了代理支持的拉动。我可以这样看吗?
    • 是的,一个封闭的拉动不会合并它:s。表示已被拒绝。但我不知道为什么!
    【解决方案2】:

    正如 Glenn 所说,tweepy 目前不支持代理。

    由于我无法解释的原因(也没有记录),大约一个月前,一个拉取请求在没有任何合并的情况下关闭。

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

    github 上显然有一个 fork(请参阅 Glenn 的回答),但我没有测试它。

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

    【讨论】:

      猜你喜欢
      • 2016-08-06
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 2021-01-20
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多