我有一個用Python編寫的腳本,可以讓我從終端消費tweets到本地託管的mongodb數據庫。爲了延長正常運行時間,我希望在Heroku上遠程託管此腳本,並將使用的推文發送到由MongoHQ託管的數據庫中。因爲我想在不使用Django的情況下執行此操作,所以我使用Flask框架將應用程序部署到Heroku(如下所述:https://devcenter.heroku.com/articles/python)。如何使用MongoHQ和Heroku(Python)遠程運行我的Flask應用程序
當我使用這個設置運行一個簡單的「hello world」應用程序時,一切都很好。但是,當我嘗試運行我的tweet消費應用程序時,它立即崩潰。我如何更改我的應用程序以使其可以與Flask/Heroku/MongoHQ設置一起使用?源代碼是:
import json
import pymongo
import tweepy
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
def __init__(self, api):
self.api = api
super(tweepy.StreamListener, self).__init__()
self.db = pymongo.MongoClient().test
def on_data(self, tweet):
self.db.tweets.insert(json.loads(tweet))
def on_error(self, status_code):
return True # Don't kill the stream
def on_timeout(self):
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener(api))
sapi.filter(track=['rooney'])
我完全是編程新手,所以我想這個問題的解決方案可能是非常簡單的。但是,我卡住了,可以真正使用一些幫助來取得進展。
我的Heroku的日誌是:國家從開始改爲墜毀 2013-08-06T10:07:44.409065 + 00:00的Heroku [web.1]:錯誤R10(啓動超時) - > Web編程未能在發佈後的60秒內綁定到$ PORT 2013-08-06T10:07:44.409351 + 00:00 heroku [web.1]:用SIGKILL停止進程 – user2161725