twitter——数据连接

 

sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程)

https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share



#测试报错
ConnectionError: HTTPSConnectionPool(host='stream.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/filter.json?delimited=length (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0ADA4030>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',)

# -*- coding: utf-8 -*- """ Created on Fri Jan 13 15:58:57 2017 @author: Administrator """ from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener #consumer key, consumer secret, access token, access secret. #我申请的Twitter API ckey=" dbCYcztxFgLSELgqGj4yipViV" csecret="Cp5FHSlqkrVWb1ArJczYZFogF94sPEhfKvdw6IxfkcJMBIMDWk" atoken="819818506292105216-vxyIAC0GXhhCqVY94g7kfm9VkSSyqh9" asecret="hq8rbVf4cNYOJmVOeeAWiUrmuo6i4enVlnuty5ySeQKfl" 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"])
豆荚加速器
twitter_api2.py 不停报错,不能正确连接Twitter,

蓝灯
完全连接不上




# -*- coding: utf-8 -*-
"""
Created on Sat Jan 14 11:11:46 2017

@author: daxiong
twitter_api2.py
"""

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import json
import sentiment_mod as s

#consumer key, consumer secret, access token, access secret.
ckey=" dbCYcztxFgLSELgqGj4yipViV"
csecret="Cp5FHSlqkrVWb1ArJczYZFogF94sPEhfKvdw6IxfkcJMBIMDWk"
atoken="819818506292105216-vxyIAC0GXhhCqVY94g7kfm9VkSSyqh9"
asecret="hq8rbVf4cNYOJmVOeeAWiUrmuo6i4enVlnuty5ySeQKfl"

#from twitterapistuff import *

class listener(StreamListener):
    
    def on_data(self, data):
        
		        all_data = json.loads(data)
		        tweet = all_data["text"]
		        sentiment_value= s.sentiment(tweet)
		        print(tweet, sentiment_value)

		        output = open("twitter-out.txt","a")
		        output.write(sentiment_value)
		        output.write('
')
		        output.close()

		        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=["happy"])

python风控评分卡建模和风控常识(博客主亲自录制视频教程)

原文地址:https://www.cnblogs.com/webRobot/p/6283312.html