patrickloeber / python-fun

Some fun and useful projects with Python
MIT License
725 stars 561 forks source link

ERROR: Exception in ASGI application for webapps -> fastapi -> uvicorn #9

Open jiapei100 opened 2 years ago

jiapei100 commented 2 years ago
➜  fastapi git:(master) ✗ uvicorn app:app --reload
INFO:     Will watch for changes in these directories: ['~/....../python-fun/webapps/fastapi']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [2387967] using watchgod
INFO:     Started server process [2387969]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:58440 - "GET / HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "~/.local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "~/.local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/fastapi/applications.py", line 259, in __call__
    await super().__call__(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/applications.py", line 119, in __call__
    await self.middleware_stack(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc
  File "~/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "~/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 87, in __call__
    raise exc
  File "~/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 76, in __call__
    await self.app(scope, receive, sender)
  File "~/.local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "~/.local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/routing.py", line 659, in __call__
    await route.handle(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/routing.py", line 61, in app
    response = await func(request)
  File "~/.local/lib/python3.8/site-packages/fastapi/routing.py", line 216, in app
    solved_result = await solve_dependencies(
  File "~/.local/lib/python3.8/site-packages/fastapi/dependencies/utils.py", line 465, in solve_dependencies
    response = response or Response(
  File "~/.local/lib/python3.8/site-packages/starlette/responses.py", line 50, in __init__
    self.init_headers(headers)
  File "~/.local/lib/python3.8/site-packages/starlette/responses.py", line 77, in init_headers
    and not (self.status_code < 200 or self.status_code in (204, 304))
TypeError: '<' not supported between instances of 'NoneType' and 'int'
INFO:     127.0.0.1:58442 - "GET /favicon.ico HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:58444 - "GET / HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "~/.local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "~/.local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/fastapi/applications.py", line 259, in __call__
    await super().__call__(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/applications.py", line 119, in __call__
    await self.middleware_stack(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc
  File "~/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "~/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 87, in __call__
    raise exc
  File "~/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 76, in __call__
    await self.app(scope, receive, sender)
  File "~/.local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "~/.local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/routing.py", line 659, in __call__
    await route.handle(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "~/.local/lib/python3.8/site-packages/starlette/routing.py", line 61, in app
    response = await func(request)
  File "~/.local/lib/python3.8/site-packages/fastapi/routing.py", line 216, in app
    solved_result = await solve_dependencies(
  File "~/.local/lib/python3.8/site-packages/fastapi/dependencies/utils.py", line 465, in solve_dependencies
    response = response or Response(
  File "~/.local/lib/python3.8/site-packages/starlette/responses.py", line 50, in __init__
    self.init_headers(headers)
  File "~/.local/lib/python3.8/site-packages/starlette/responses.py", line 77, in init_headers
    and not (self.status_code < 200 or self.status_code in (204, 304))
TypeError: '<' not supported between instances of 'NoneType' and 'int'
^CINFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [2387969]
INFO:     Stopping reloader process [2387967]
stonebig commented 2 years ago

so for me it works, even on pypy3.8-v7.3.9-win64, when I do this :

pip install fastapi "uvicorn[standard]" python-multipart sqlalchemy jinja2

python -m webbrowser -t "http://127.0.0.1:8000/"
python -m webbrowser -t "http://127.0.0.1:8000/docs"

uvicorn app:app --reload

image