我写了一个脚本来连接twitter的API。 这个脚本在我的电脑上运行得很好。 这是脚本,它在所有推文中包含“car”一词:
from tweepy.streaming import Stream
from tweepy import OAuthHandler
from tweepy import StreamListener
ckey='myCustomerKey'
csecret='myCustomerSecret'
atoken='myToken'
asecret='mySecret'
class listener(StreamListener):
def on_data(self,data):
print data
return True
def on_error(self, status):
print status
auth=OAuthHandler(ckey,csecret)
auth.set_access_token(atoken, asecret)
twitterStream=Stream(auth, listener())
twitterStream.filter(track=['car'])
正如我所说,它在我的机器上运行良好。 但是,当我将此脚本复制到外部服务器(当然,下载相关模块(tweepy))时 - 我收到此错误:
runfile('Z:/Data/twitter/grab_tweets.py', wdir='Z:/Data/twitter')
Traceback (most recent call last):
File "<ipython-input-5-74327b031634>", line 1, in <module>
runfile('Z:/Data/twitter/grab_tweets.py', wdir='Z:/Data/twitter')
File "C:\Anaconda2\Lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Anaconda2\Lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "Z:/Data/twitter/grab_tweets.py", line 25, in <module>
twitterStream.filter(track=['car'])
File "build\bdist.win-amd64\egg\tweepy\streaming.py", line 445, in filter
self._start(async)
File "build\bdist.win-amd64\egg\tweepy\streaming.py", line 361, in _start
self._run()
File "build\bdist.win-amd64\egg\tweepy\streaming.py", line 294, in _run
raise exception
ConnectionError: ('Connection aborted.', error(10053, 'An established connection was aborted by the software in your host machine')
我看了这个错误 - 我看到了一些关于防火墙的东西,所以我试图将其关闭 - 但它没有帮助。
有什么想法吗?