2016-07-22 5 views
0

TwitterのAPIを使用してデータベースにツイートをストリーミングしようとすると:私はPythonスクリプトを使用してTwitterからのつぶやきを取得しようとしているが、私はスクリプトを実行するたびに、私は次のエラーを取得するPythonの

from tweepy import Stream 
from tweepy import OAuthHandler 
from tweepy.streaming import StreamListener 
import MySQLdb 
import json 

conn = MySQLdb.connect("localhost","root","","lordstest") 

c = conn.cursor() 

ckey="kLqq9kLLnYzArceD7ymqlVEqS" 
csecret="DxQQiynR13JYMgVf9ltCOHAM28Ai3gCzODIV3vj0OTIiKfShsz" 

atoken="480488826-7iJ8Yq86ASy0u9HaSFO1ZCl5xlKakabKEsWaHVHh" 
asecret="BJm6MdyrFRDObHc3sYSDqeStZYZlgIyHtRwFGzJ8XevdL" 

class listener(StreamListener): 

    def on_data(self, data): 
     all_data = json.loads(data) 

     tweet = all_data["text"] 

     username = all_data["user"]["screen_name"] 

     c.execute("INSERT INTO Lords (username, tweet) VALUES (%s,%s)", 
      (username, tweet)) 

     conn.commit() 

     print((username,tweet)) 

     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=["Lords test"],languages= ["en"]) 

これをどのように修正することができますか?

+0

ネットワークに問題はありますか? – masnun

答えて

0

受信したエラーは何ですか?私が理解していることは、モンゴーのようにnosqlに入れなければならない場合です。私はcode on Githubを持っています。

関連する問題