3

我正在尝试将一个简单的烧瓶应用程序部署到 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=

我知道它的出现是因为我的网络测功机崩溃了,但我只是不知道它为什么会崩溃。

这是我的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)

任何帮助将非常感激!

4

0 回答 0