我試圖連接到任何地方的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上的魅力。
任何想法都會超過歡迎,謝謝!
嘿,thx爲您的答案!我看到一個月前關閉了代理支持。我可以這樣看嗎? – jlengrand
是的,封閉的拉不合並:s。意味着它已被拒絕。但我不知道爲什麼! – jlengrand