Giter Club home page Giter Club logo

Comments (6)

tiangolo avatar tiangolo commented on May 22, 2024 4

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: tiangolo/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.

JSchoreels avatar JSchoreels commented on May 22, 2024 1

Thank you for the feedback @tiangolo ! Closing the issue

from uvicorn-gunicorn-fastapi-docker.

tiangolo avatar tiangolo commented on May 22, 2024 1

Thanks for reporting back and closing the issue ๐Ÿ‘

from uvicorn-gunicorn-fastapi-docker.

AlexWootton avatar AlexWootton commented on May 22, 2024

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.

AlexWootton avatar AlexWootton commented on May 22, 2024

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.

tiangolo avatar tiangolo commented on May 22, 2024

@AlexWootton

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.