Tweepyを使用してストリーミングAPIにアクセスし、JSONファイルに格納しています。 コードは正常に見えるが、私はこのエラーを得続ける: はAttributeError:「ここNoneType」オブジェクトが属性「ストリップ」を持っていないつぶやきtweepyを使用したライブストリーミング
import sys
import tweepy
import json
consumer_key = 'XXXX'
consumer_secret = 'XXXX'
access_key = 'XXXX'
access_secret = 'XXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
file = open('today.txt', 'a')
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print (status.text)
def on_data(self, data):
json_data = json.loads(data)
file.write(str(json_data))
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['twitter'])
エラーが最後の行です。 私はストリームがnullを返すと思いますので、フィルタリングしようとしているときにエラーが発生しています。 助けてください!