尝试在 Heroku 上部署时出现 H10 应用程序崩溃错误后出现文件引用错误

时间:2021-05-18 13:14:38

标签: python html reactjs heroku

我在运行 heroku logs --tail 命令后收到此错误。

2021-05-18T13:06:18.026204+00:00 app[web.1]: File "/app/api/app.py", line 5, in <module>
2021-05-18T13:06:18.026205+00:00 app[web.1]: from HelloApiHandler import HelloApiHandler
2021-05-18T13:06:18.026205+00:00 app[web.1]: ModuleNotFoundError: No module named 'HelloApiHandler'

2021-05-18T13:06:50.495217+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET 
path="/" host=deploy-testv1.herokuapp.com request_id=7790eadd-a43b-49db-8eb0-27fff8d7a6bf 
fwd="123.201.36.104" dyno= connect= service= status=503 bytes= protocol=https

2021-05-18T13:06:50.785798+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET 
path="/favicon.ico" host=deploy-testv1.herokuapp.com request_id=0d7d0f68-a99b-4783-af40-cb80f17b825b 
fwd="123.201.36.104" dyno= connect= service= status=503 bytes= protocol=https

这是我在第 5 行收到错误的 app.py 文件:

from flask import Flask, send_from_directory
from flask_restful import Api, Resource, reqparse
from flask_cors import CORS 
# from api import HelloApiHandler
from HelloApiHandler import HelloApiHandler

# app = Flask(__name__, static_url_path='', static_folder='../build')
app = Flask(__name__, static_url_path='', static_folder='../build')
# CORS(app) 
api = Api(app)

@app.route("/", defaults={'path':''})
def serve(path):
    return send_from_directory(app.static_folder,'index.html')

api.add_resource(HelloApiHandler, '/flask/hello')

这是 HelloApiHandler.py 文件:

from flask_restful import Api, Resource, reqparse

class HelloApiHandler(Resource):
  def get(self):
    return {
      'resultStatus': 'SUCCESS',
      'message': "Hello Api Handler"
      }

  def post(self):
    print(self)
    parser = reqparse.RequestParser()
    parser.add_argument('type', type=str)
    parser.add_argument('message', type=str)

    args = parser.parse_args()

    print(args)
    # note, the post req from frontend needs to match the strings here (e.g. 'type and 'message')

    request_type = args['type']
    request_json = args['message']
    # ret_status, ret_msg = ReturnData(request_type, request_json)
    # currently just returning the req straight
    ret_status = request_type
    ret_msg = request_json

    if ret_msg:
      message = "Your Message Requested: {}".format(ret_msg)
    else:
      message = "No Msg"
    
    final_ret = {"status": "Success", "message": message}

    return final_ret

我的档案:

web: gunicorn api.app:app

我觉得我正确地导入了 HelloApiHandler 文件,但 heroku 日志仍然抛出错误。什么原因?

目录结构:

api
  venv
  app.py
  HelloApiHandler.py
  requirements.txt
build
node_modules
public
src
Procfile
package.json
requirements.txt
  

0 个答案:

没有答案