将烧瓶应用程序部署到Heroku - 错误H10(应用程序崩溃)

时间:2016-05-06 13:57:28

标签: python heroku flask server dyno

我正在尝试将一个简单的烧瓶应用程序部署到Heroku,它在本地工作正常,但在部署到Heroku时我收到此错误:

2016-05-05T18:39:24.897207+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/favicon.ico" host=read-
laterr.herokuapp.com request_id=2ab420c2-64df-4544-9aaf-675ae5f5abfa 
fwd="87.56.186.149" dyno= connect= service= status=503 bytes=

我知道这是因为我的网络dyno崩溃,但我只是不知道为什么它会崩溃。

这是我的Procfile:

web: gunicorn app:app

如果我只是部署一个hello应用程序它可以工作,但如果我在app.py中部署以下代码则不行:

我的app.py:

from __future__ import absolute_import, print_function
from tweepy import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import os
import json
import time
from flask import Flask, render_template

app = Flask(__name__)


@app.route("/")
def index():
    return render_template("index.html", articles=sorted(articles, key=lambda article: article["liked_on"], reverse=True))


consumer_key="xxxkeyxxx"
consumer_secret="xxxsecretxxx"
access_token="xxxtokenxxx"
access_token_secret="xxxtokensecretxxx"

articles = []

class LikedTweetsListener(StreamListener):
    def on_data(self, data):
        tweet = json.loads(data)
        if 'event' in tweet and tweet['event'] == "favorite":
            liked_tweet = tweet["target_object"]
            liked_tweet_text = liked_tweet["text"]
            story_url = extract_url(liked_tweet)
            if story_url:
                article = extract_article(story_url)
                if article:
                    article['story_url'] = story_url
                    article['liked_on'] = time.time()
                    articles.append(article)
        return True

    def on_error(self, status):
        print("Error status received : {0}".format(status))


def extract_url(liked_tweet):
    url_entities = liked_tweet["entities"]["urls"]
    if url_entities and len(url_entities) > 0:
        return url_entities[0]['expanded_url']
    else:
        return None


from newspaper import Article

def extract_article(story_url):
    article = Article(story_url)
    article.download()
    article.parse()
    title = article.title
    img = article.top_image
    publish_date = article.publish_date
    text = article.text.split('\n\n')[0] if article.text else ""
    return {
        'title':title,
        'img':img,
        'publish_date':publish_date,
        'text':text.encode('ascii','ignore')
    }


if __name__ == '__main__':
    l = LikedTweetsListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, l)
    stream.userstream(async=True)

    port = int(os.environ.get('PORT', 33507))
    app.run(host='0.0.0.0', port=port)

非常感谢任何帮助!

0 个答案:

没有答案