2

The Error:

enter image description here

Command Used to Run:

C:\Users\super\Desktop\Work\Charges2> uvicorn main:app --reload

Console Status:

PS C:\Users\super\Desktop\Work\Charges2> uvicorn main:app --reload
INFO:     Will watch for changes in these directories: ['C:\\Users\\super\\Desktop\\Work\\Charges2']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [69628] using statreload
WARNING:  The --reload flag should not be used in production on Windows.
INFO:     Started server process [72184]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:61648 - "GET / HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 364, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\fastapi\applications.py", line 212, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\applications.py", line 119, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
    raise exc
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\exceptions.py", line 87, in __call__
    raise exc
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\exceptions.py", line 76, in __call__
    await self.app(scope, receive, sender)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\routing.py", line 659, in __call__
    await route.handle(scope, receive, send)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\site-packages\starlette\responses.py", line 50, in __init__
    self.init_headers(headers)
  File "C:\Users\super\Desktop\Work\Charges2\venv\lib\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'

Code (main.py):

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

Folder Structure:

enter image description here

Pip Freeze:

anyio==3.5.0
asgiref==3.5.0
click==8.0.3
colorama==0.4.4
fastapi==0.73.0
h11==0.13.0
idna==3.3
pydantic==1.9.0
sniffio==1.2.0
starlette==0.18.0
typing_extensions==4.1.1
uvicorn==0.17.4

Using Python 3.10.2

9
  • Please post error messages as text. Commented Feb 15, 2022 at 21:35
  • @SuperStormer Okay, I posted console status as text Commented Feb 15, 2022 at 21:37
  • Could you please provide the versions of the packages in your environment? (pip freeze) Commented Feb 15, 2022 at 21:39
  • 1
    @NoName I get this error when trying to install your packages with pip install -r requirements.txt: ``` ERROR: Cannot install -r requirements.txt (line 5) and starlette==0.18.0 because these package versions have conflicting dependencies. The conflict is caused by: The user requested starlette==0.18.0 fastapi 0.73.0 depends on starlette==0.17.1 ``` There must be some conflict between your dependencies. Commented Feb 15, 2022 at 21:49
  • 1
    @decorator-factory Oh my god it works! Can you put your suggestion as an answer so I can checkmark? And how do I know which packages I can update in the future if new versions come out? Commented Feb 15, 2022 at 22:00

2 Answers 2

4

I get this error when trying to install your packages with pip install -r requirements.txt:

ERROR: Cannot install -r requirements.txt (line 5) and starlette==0.18.0
because these package versions have conflicting dependencies.

The conflict is caused by:
The user requested starlette==0.18.0
fastapi 0.73.0 depends on starlette==0.17.1

There must be some conflict between your dependencies. Try making a clean install of FastAPI.

If you suspect that there's a version issue, try installing your requirements from scratch.


If you want to prevent such conflicts in the future, a popular solution is to use a dependency management tool, such as pipenv or poetry.

Sign up to request clarification or add additional context in comments.

Comments

0
which uvicorn
which python

I got same error when run Python 3.10.x from virtual environment, but uvicorn was external with Python 3.7. Installing uvicorn to virtialenv solved the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.