这里为了在twitter api获取数据,运用stream api获取数据进行测试,在根据官方教程出现问题,采纳的教程链接 https://www.youtube.com/watch?v=pUUxmvvl2FE
代码:
from tweepy import Streamfrom tweepy import OAuthHandler
from tweepy.streaming import StreamListener
atoken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
asecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ckey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
csecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
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"])
这里密钥相关采用的是我申请的,但是在运行的时候出现如下的调试问题
raceback (most recent call last):
File "D:/project/python_project/TestStream/StreamApi.py", line 23, in <module>
twitterStream.filter(track=["car"])
File "build\bdist.win-amd64\egg\tweepy\streaming.py", line 445, in filter
File "build\bdist.win-amd64\egg\tweepy\streaming.py", line 361, in _start
File "build\bdist.win-amd64\egg\tweepy\streaming.py", line 294, in _run
requests.exceptions.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 0x0000000002F7D5F8>: Failed to establish a new connection: [Errno 10060] ',))
另外:我使用的是python 2.7 具体问题原因是什么请帮忙指出
|