Heroku 应用错误 - code=H10 desc="应用程序崩溃"

3

我正在尝试在Heroku上部署一个Dash应用程序。

除了当我运行heroku open时出现“应用程序错误”之外,一切都正常(本地也是如此):

enter image description here

然后运行heroku logs --tail,会得到以下输出:

2019-11-22T22:55:41.598239+00:00 heroku[web.1]: State changed from up to crashed
2019-11-22T22:55:41.587218+00:00 heroku[web.1]: Process exited with status 3
2019-11-22T22:55:42.000000+00:00 app[api]: Build succeeded
2019-11-22T22:55:59.485489+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=romania2019.herokuapp.com request_id=d48fde4a-bd7e-47e2-9a21-bdf589ef281a fwd="152.115.83.242" dyno= connect= service= status=503 bytes= protocol=https
2019-11-22T22:55:59.851491+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=romania2019.herokuapp.com request_id=b6bbb5e8-8667-42f2-b083-b7bf26b5ae14 fwd="152.115.83.242" dyno= connect= service= status=503 bytes= protocol=https

你有什么建议我接下来该去哪里寻找?


这是我正在尝试部署的app.py文件:

import datetime
import time

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly
from dash.dependencies import Input, Output

import numpy as np
from selenium import webdriver

url = 'https://prezenta.bec.ro/prezidentiale24112019/abroad-precincts'


profile = webdriver.FirefoxProfile()
profile.set_preference("browser.preferences.instantApply",True)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", 
                       "text/plain, application/octet-stream, application/binary, text/csv, application/csv, application/excel, text/comma-separated-values, text/xml, application/xml")
profile.set_preference("browser.helperApps.alwaysAsk.force",False)
profile.set_preference("browser.download.manager.showWhenStarting",False)
profile.set_preference("browser.download.folderList",1)


options = webdriver.FirefoxOptions()
options.headless = True

# create a new Firefox session
driver = webdriver.Firefox(firefox_profile=profile, options=options)
driver.implicitly_wait(30)
driver.get(url)

# Find button and click on it
ELEMENT = driver.find_element_by_xpath('//*[@id="root"]/main/section/div[1]/div[1]/div[5]/div/div[2]/div/h2')

def update(ELEMENT):
    # time.sleep(2.9)
    return int(ELEMENT.text.replace('.', ''))


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

server = app.server

app.layout = html.Div(
    html.Div([
        html.H4('ROMANIA - Presidential Elections Live Feed'),
        html.Div(id='live-update-text'),
        dcc.Graph(id='live-update-graph'),
        dcc.Interval(
            id='interval-component',
            interval=60*1000, # in milliseconds
            n_intervals=0
        )
    ])
)

time.sleep(5)
@app.callback(Output('live-update-text', 'children'),
              [Input('interval-component', 'n_intervals')])
def update_metrics(n):
    no = update(ELEMENT)
    style = {'padding': '5px', 'fontSize': '16px'}
    return [
        html.Span('Voters: {}'.format(no), style=style),
        html.Span('Voters/Min: {}'.format(np.diff(data['number'])[-5:].mean()), style=style)
    ]


data = {'time': [], 'number': []}

# Multiple components can update everytime interval gets fired.
@app.callback(Output('live-update-graph', 'figure'),
              [Input('interval-component', 'n_intervals')])
def update_graph_live(n):
    # Collect some data
    data['time'].append(datetime.datetime.now()) # + datetime.timedelta(seconds=3))

    try:
        no = update(ELEMENT)
        data['number'].append(no)
    except:
        data['number'].append(no)



    # Create the graph with subplots
    fig = plotly.subplots.make_subplots(rows=2, cols=1, vertical_spacing=0.1)
    fig['layout']['margin'] = {
        'l': 30, 'r': 10, 'b': 30, 't': 10
    }
    fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'left'}

    fig.append_trace({
        'x': data['time'],
        'y': data['number'],
        'name': 'Voters',
        'type': 'scatter'
    }, 1, 1)
    fig.append_trace({
        'x': data['time'],
        'y': np.diff(data['number']),
        'text': data['time'],
        'name': 'Voters / Min',
        'type': 'scatter'
    }, 2, 1)
    fig.layout.update(height=800, )

    return fig


if __name__ == '__main__':
    app.run_server(debug=True)

它基本上会读取选民数量,并显示每分钟的投票数。

我一直遵循的部署说明在这里:https://dash.plot.ly/deployment


同样的错误在这里,仍然找不到解决方案... - Lucas Lopes
为什么这个问题没有答案? - Bawantha
1个回答

0

打开你的 Git Bash 并输入 log --tails 命令,它会显示错误类型 H10,这是由于一些依赖项缺失或者你的 Procfile 配置不正确导致的应用程序崩溃。尝试阅读错误类型并查看你的代码。如果你的应用在本地主机上运行正常,请尝试使用以下命令:

web: gunicorn index:server --preload --timeout60。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接