0

I have a script written in Python that lets me consume tweets from Terminal into a locally hosted mongodb database. To improve uptime, I would like to host this script remotely on Heroku and to shoot the consumed tweets into a database hosted with MongoHQ. As I would like to do this without using Django, I use the Flask framework to deploy the app to Heroku (described here: https://devcenter.heroku.com/articles/python).

When I run a simple "hello world" app using this setup, everything is fine. However, when I try to run my tweet consuming app, it immediately crashes. How can I change my app to that it will work with the Flask/Heroku/MongoHQ setup? The source code is:

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'])

I am completely new to programming so I imagine the solution to this problem might well be quite straight forward. However, I am stuck and could really use some help to progress.

user2161725
  • 667
  • 2
  • 7
  • 12
  • My heroku log is: State changed from starting to crashed 2013-08-06T10:07:44.409065+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2013-08-06T10:07:44.409351+00:00 heroku[web.1]: Stopping process with SIGKILL – user2161725 Aug 07 '13 at 10:39

1 Answers1

0

It's hard to debug without more information, but my first guess is that you don't have the dependancies installed.

Heroku gives you a clean python environment. However, you need special libraries like tweepy that don't get installed by default. Thus, you have to let Heroku know to install these.

You'll need to use pip and a requirements.txt document which lists out all the libraries that you are trying to use as well as what version numbers.

https://devcenter.heroku.com/articles/python-pip

Liyan Chang
  • 7,721
  • 3
  • 39
  • 59
  • The second guess is that you are connecting to a database that isn't responding. https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout – Liyan Chang Aug 09 '13 at 23:27