Comments (6)
Thanks for the report guys. It should be fixed now.
Details
The problem was that this image had an older version of FastAPI installed. A version from before FastAPI had its own HTTPException
.
But the root problem is that when I released a new version of FastAPI, this image was not updated automatically.
But I fixed it here: fastapi/fastapi#65
Now, when there's a new version of FastAPI, a build of this image will be triggered automatically, so it will always be fresh.
Please try a recent version with:
docker pull tiangolo/uvicorn-gunicorn-fastapi:python3.7-alpine3.8
and
docker pull tiangolo/uvicorn-gunicorn-fastapi:python3.7
and let me know if it's working for you.
HTTPException
details:
FastAPI has its own HTTPException
to be able to provide custom headers in it. Which is useful for some kinds of authentication/security. Apart from that, it's equivalent to Starlette's HTTPException
(inherits from it).
In summary, you can also use Starlette's HTTPException
directly and it should work well too.
from uvicorn-gunicorn-fastapi-docker.
Thank you for the feedback @tiangolo ! Closing the issue
from uvicorn-gunicorn-fastapi-docker.
Thanks for reporting back and closing the issue ๐
from uvicorn-gunicorn-fastapi-docker.
Same for me. When running tiangolo/uvicorn-gunicorn-fastapi:python3.7
, importing HTTPException
from fastapi
results in the following error:
ImportError: cannot import name 'HTTPException' from 'starlette' (/usr/local/lib/python3.7/site-packages/starlette/__init__.py)
To get around this I am importing directly from Starlette as @JSchoreels mentions above.
Workaround
instead of:
from fastapi import HTTPException
use:
from starlette.exceptions import HTTPException
from uvicorn-gunicorn-fastapi-docker.
Perfect, thanks @tiangolo
For what itโs worth I decided it was probably better practice to use the Docker image that this image is based on and install FastAPI and any dependencies from a requirements.txt in one fell swoop!
Good to know that this image should always be running the latest release from now on though ๐
Oh and thanks for all your hard work. Iโve only been playing with FastAPI for a short while but from what Iโve seen of it so far itโs great! Excited to use it in a project in the near future
from uvicorn-gunicorn-fastapi-docker.
For what itโs worth I decided it was probably better practice to use the Docker image that this image is based on and install FastAPI and any dependencies from a requirements.txt in one fell swoop!
I agree! In fact, I do that in the project generators: https://github.com/tiangolo/full-stack-fastapi-postgresql
Good to know that this image should always be running the latest release from now on though ๐
๐ โ๏ธ
Oh and thanks for all your hard work. Iโve only been playing with FastAPI for a short while but from what Iโve seen of it so far itโs great! Excited to use it in a project in the near future
โบ๏ธ
That's great to hear! ๐ ๐
from uvicorn-gunicorn-fastapi-docker.
Related Issues (20)
- Application does not start up when combining this image and a database connection in Linux CentOS. HOT 4
- Upgrade from python3.8 to python3.11 fails HOT 1
- ModuleNotFoundError: No module named 'app' HOT 2
- APScheduler logs not showing in docker HOT 1
- websocket can not use
- Deploying HuggingFace model/pipeline using uvicorn-gunicorn-fastapi-docker on Google Cloud Run HOT 2
- Is --proxy-headers applied in the uvicorn CMD in the image? HOT 1
- getting timeout 504 in 1 minute
- Support for Apple sillicon
- New docker-image may be broken HOT 1
- apt-get update not working on specific version
- container build fails with pydantic-settings HOT 1
- Uvicorn -gunicorn-fastapi-docker
- Runtime Error: Can't start new thread HOT 2
- linux/arm64/v8 not supported HOT 2
- Unexpected Redirection of `/docs` Endpoint with Custom `APP_MODULE` Setup
- Current gunicorn version does not support Python 3.11 HOT 1
- Base Dockerfile HOT 3
- pydantic_settings package not supported
- Update fastapi to support Pydantic2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uvicorn-gunicorn-fastapi-docker.