我正在尝试使用Tweepy返回一个Tweet样本。当我在我的苹果电脑上运行.py文件时,我能够成功地接收和解析推文,然而,当我在亚马逊网络服务EC2上的Ubuntu实例中运行相同的代码时,流连接没有保持打开,文件关闭。
我试过找出Twitter是否抛出了任何错误,但是尝试了一下,除了block不抛出任何错误。
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print (status.text)
#Sets up our streaming listener
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout = 1000)
#Calls the streaming listener
def streaming():
try:
print ("Starting Streaming")
streaming_api.sample()
print("Still streaming")
except Exception as e:
print (e)
print (sys.stderr, 'Encountered Exception:', e)
time.sleep(600)
streaming()
#Calls our streaming function
streaming()在我的mac上,它成功地打印了推文,并保留了一个活动的连接。
当我将文件上传到Ubuntu EC2实例并运行它时,它只返回:"Starting Streaming“”Starting“,然后退出程序。
发布于 2019-09-08 05:55:28
事实证明,EC2实例的日期与真实时间相差了20分钟。
用户可以通过键入以下命令找到Ubuntu实例的日期:
可以通过键入以下命令来更新时间: sudo ntpdate time.nist.gov
https://stackoverflow.com/questions/57837689
复制相似问题