Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在heroku中部署fastapi时出现h10错误_Python_Heroku_Fastapi - Fatal编程技术网

Python 在heroku中部署fastapi时出现h10错误

Python 在heroku中部署fastapi时出现h10错误,python,heroku,fastapi,Python,Heroku,Fastapi,我已经在heroku中部署了fastapi应用程序,部署成功,但在启动应用程序时。我的浏览器正在显示此消息。(下面的屏幕截图) 我通过粘贴代码更新了我的问题,也更新了日志中的错误 我已经检查了日志,它在下面显示了这个错误 2021-05-31T09:31:47.954921+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=newsscr

我已经在heroku中部署了fastapi应用程序,部署成功,但在启动应用程序时。我的浏览器正在显示此消息。(下面的屏幕截图)

我通过粘贴代码更新了我的问题,也更新了日志中的错误

我已经检查了日志,它在下面显示了这个错误

2021-05-31T09:31:47.954921+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=newsscrapperdemo.herokuapp.com request_id=a4f73b48-f728-4515-afef-38c64e10f0cd fwd="157.45.236.3" dyno= connect= service= status=503 bytes= protocol=https
2021-05-31T09:31:49.012665+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=newsscrapperdemo.herokuapp.com request_id=da7409af-fac0-4e67-99a0-5a9b11a9a697 fwd="157.45.236.3" dyno= connect= service= status=503 bytes= protocol=https
2021-05-31T10:09:54.199508+00:00 app[web.1]:     from models import User_Pydantic, UserIn_Pydantic, User
2021-05-31T10:09:54.199558+00:00 app[web.1]: ModuleNotFoundError: No module named 'models'
2021-05-31T10:10:51.392906+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-05-31T10:10:51.468480+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-05-31T10:10:51.587648+00:00 heroku[web.1]: Process exited with status 137
2021-05-31T10:10:51.683564+00:00 heroku[web.1]: State changed from starting to crashed
我的proc文件如下所示

web: uvicorn environment.main:app --host 0.0.0.0 --port $PORT --workers 2

尝试运行heroku logs--tail,正如消息告诉您的那样,您将看到异常的原因并在此处共享。嗨,sergey,我已经在日志中粘贴了错误。请帮助我,我也更新了我的答案
**main.py**

from fastapi import FastAPI, Request, Form, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.templating import Jinja2Templates
from models import User_Pydantic, UserIn_Pydantic, User
from tortoise.contrib.fastapi import register_tortoise, HTTPNotFoundError
from typing import List
from fastapi.encoders import jsonable_encoder
import requests
from bs4 import BeautifulSoup as BS


app = FastAPI()

register_tortoise(
    app,
    db_url="sqlite://store_db.db",
    modules={'models':['models']},
    generate_schemas = True,
    add_exception_handlers = True,
    

)


templates = Jinja2Templates(directory="templates")



@app.get("/", response_class=HTMLResponse)
async def login_page(request :Request):
    return templates.TemplateResponse("index.html", {"request":request})


@app.post("/loginsuccess/", response_class=HTMLResponse)
async def login_success(request: Request, username: str = Form(...), password: str = Form(...)):
    p = await User_Pydantic.from_tortoise_orm(await User.get(username=username, password=password))
    json_compatible_item_data = jsonable_encoder(p)
    print(json_compatible_item_data, "33333333333333333333333")
    if json_compatible_item_data is not None:
        
        print(json_compatible_item_data["username"], "22222222222222222")
        return templates.TemplateResponse("homepage.html", {"request": request, "username":username})
    else:
        print("NOOOOOOOOOOOOOOOOO")
        status_code:int
        status_code = 500
        return templates.TemplateResponse("index.html", {"request":request, "status_code":status_code})
    

**models.py***


from tortoise import fields
from tortoise import models
from tortoise.contrib.pydantic import pydantic_model_creator

class User(models.Model):
    username = fields.CharField(max_length=50, unique=True)
    password = fields.CharField(max_length=50)


    class PydanticMeta:
        pass

User_Pydantic = pydantic_model_creator(User, name="User")
UserIn_Pydantic = pydantic_model_creator(User, name="UserIn", exclude_readonly=True)