簡體   English   中英

Python-連接Twitter的API

[英]Python - connecting with twitter's API

我寫了一個腳本來連接Twitter的API。 該腳本可以在我的PC上完美運行。 這是腳本,其中包含所有帶有“ 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') 

我查找了此錯誤-我看到了有關防火牆的某些內容,因此我嘗試將其關閉-但這沒有幫助。

任何想法?

您需要使用代理服務器進行身份驗證。 我不確定tweepy是否可行。

您可以嘗試使用支持代理身份驗證的TwitterAPI 請參閱doc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM