Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 16:11
    indepndnt commented #999
  • 13:36
    MrYZhou closed #5269
  • 13:35
    MrYZhou opened #5269
  • 13:35
    MrYZhou labeled #5269
  • 09:38
    Abutler101 closed #4445
  • Aug 12 20:23
    Ancieg commented #5172
  • Aug 12 18:53
    iudeen commented #5268
  • Aug 12 18:50
    iudeen commented #5268
  • Aug 12 18:49
    iudeen commented #5268
  • Aug 12 15:20
    Prof1-web edited #5268
  • Aug 12 15:20
    Prof1-web edited #5268
  • Aug 12 15:19
    Prof1-web opened #5268
  • Aug 12 15:19
    Prof1-web labeled #5268
  • Aug 12 15:00
    TomEverson closed #5263
  • Aug 12 15:00
    TomEverson commented #5263
  • Aug 12 14:40
    TomEverson commented #5263
  • Aug 12 14:38
    TomEverson commented #5263
  • Aug 12 14:28
    bersena911 commented #5091
  • Aug 12 13:46
    Galaxy0419 edited #5267
  • Aug 12 13:37
    codecov[bot] commented #5267
sourasis
@sourasis:matrix.org
[m]
subject = report_recipients_df[report_recipients_df['report'] == report_title]['subject'].iloc[0]. \
replace('<date>', hp.current_date)
sourasis
@sourasis:matrix.org
[m]
:point_up: Edit: file_name = "Report_" + city_name + '_' + hp.current_datetime + ".xlsx"
sourasis
@sourasis:matrix.org
[m]
I have put all of these now inside a function and calling the function instead. That is working. Thanks @agronholm again for pointing to the solution
sourasis
@sourasis:matrix.org
[m]
However I am still stuck on my other problem of having a gunicorn daemon render as per code changes without needing to restart gunicorn. The --reload parameter doesnt seem to be working . Tried with --reload_engine parameter as well but with no luck. I do a 'git pull' to change my code.
Alex Grönholm
@agronholm
wait, you need to do git pull to update your code? where do you expect gunicorn to get the new code from then?
sourasis
@sourasis:matrix.org
[m]
I was hoping that --reload will detect the change in my main.py and recompile the app +reset the workers, whenever I do a git pull.
Alex Grönholm
@agronholm
hmm..that it should do
sourasis
@sourasis:matrix.org
[m]
Yes. Thought so. But its not happening like that. Should I raise a ticket on Gunicorn forum or is there some other way to do this?
Alex Grönholm
@agronholm
what strikes me as odd that you're using gunicorn instead of uvicorn with fastapi
fastapi is an ASGI, not WSGI based framework
sourasis
@sourasis:matrix.org
[m]
True. My issue is I need a server running continuously in the background to attend to any API calls in production. I found that uvicorn is not recommended in production + it doesn't have a way to run a daemon in the background. So, had to use Gunicorn to do this. I must admit I am new to this and might be doing this absolutely wrong. If there is some other way to run a uvicorn daemon then please let me know, will implement that
Alex Grönholm
@agronholm
how are you deploying your API server? usually you would deploy it as a container, or as a systemd service
in either case running as a daemon is not required for the ASGI server
sourasis
@sourasis:matrix.org
[m]
I am deploying it on a Virtual Linux Machine. I think I need to try as a systemd service with uvicorn and --reload param. Let me try that and come back with an update. But note that I have tried running it on uvicorn in various ways in the background including "Screen" command in linux, but everytime it goes into background the APIs stop working. So, thats when I thought it does need to run in some kind of daemon mode and tried gunicorn
6 replies
sourasis
@sourasis:matrix.org
[m]
Ok. In our case, we have a legacy data reporting system which was written years ago and now we are porting that to fastAPI. So , data engineering team is adding a new API to the fastAPI almost every few days. 🙄
16 replies
eCrimeLabs
@eCrimeLabs

Hey all,

Currently on my first project so bear with me :) I'm trying to build a small webapp that in will take the input from a get request and then is has to check if each "value" is in a list of values

@app.get("/v1/feeds/{feed}/{type}/{age}/{output}", tags=["feeds"])
3 replies
anyone have an example on such
The source of the positive list is a json blob
{
    "feed": ["movie", "music"],
    "type": ["online", "offline"],
    "age": ["1900", "2000"],
    "output": ["json", "xml"]
}
zuntaruk
@zuntaruk:matrix.org
[m]

Assuming my assumption is correct, you'll want to look at this part of the docs:

https://fastapi.tiangolo.com/tutorial/path-params/#create-an-enum-class

For you it might look something like this:

from enum import Enum

from fastapi import FastAPI


class Feed(str, Enum):
    movie = "movie"
    music = "music"

class FeedType(str, Enum):
    online = "online"
    offline = "offline"

class FeedAge(str, Enum):
    nineteen_hundred = "1900"
    two_thousand = "2000"

class FeedOutput(str, Enum):
    json = "json"
    xml = "xml"

app = FastAPI()

@app.get("/v1/feeds/{feed}/{type}/{age}/{output}", tags=["feeds"])
async def get_feed(
    feed: Feed, type: FeedType, age: FeedAge, output: FeedOutput
):

This is a handy way of going about it because FastAPI (via Pydantic) will handle the validation for you on all those path parameters.

eCrimeLabs
@eCrimeLabs
Thanks @zuntaruk:matrix.org
zuntaruk
@zuntaruk:matrix.org
[m]
Guess it depends on how far down that rabbit hole you wanna go, eh? hehehe
Noel
@RothNRK

Hello I'm trying to use Pydantic with Form data.
pydantic==1.9.1
fastapi==0.79.0

This code works with my tests

@router.post("/foo/")
async def foo(file: UploadFile = File(), name: str = Form()):
    return {
        "file_size": file.content_type,
        "name": name,
    }

While if I try and use a Pydantic model with dependancy injection it will fail with: `'{"detail":[{"loc":["query","name"],"msg":"field required","type":"value_error.missing"}]}'

class Base(BaseModel):
    name: str = Form()


@router.post("/foo/")
async def foo(file: UploadFile = File(), base: Base = Depends()):
    breakpoint()
    return {
        "file_size": file.content_type,
        "name": base.name,
    }

This seems like a straight forward application of Depends. I would appreciate any direction.

3 replies
nitinbhattdev
@nitinbhattdev
Question regarding cookies: So when I am running code locally, code is unable to capture the cookies, meanwhile the same code running on server is running flawless, can anyone guide on this
Avihai Ben-David
@avihaibd
Question regarding oauth2 flow:
From what I see in documentation and code, FastAPI OAuth2 definitions assumes an authentication token already exists.
I also found some alternatives to make FastAPI the authentication service which implements the auth protocols.
What would be the suggested solution to implement full solution that allows users login via 3rd party auth server, e.g. google or AWS Cognito, that includes full user authentication flow and API scoped access?
Ryan Truran
@RyanTruran
can someone help me with this error?
TypeError: _FunctionWrapperBase.call() got multiple values for argument 'self'
Its coming from fastapi/routing.py
the code itself works fine for others in my group but on my m1 mac i get this TypeError.
I feel like its a configuration issue with my system but i dont have the slightest idea how to troubleshoot.
dreamer
@dromer
hmmm, I'm trying to deploy fastapi using uvicorn on a k8s namespace. however it seems that if I have uvicorn listen on default (127.0.0.1) the ingress route is just ignored by the pod. any suggestions on how to configure the ingress? (we're using traefik)
(I tried using the pod address, but that fails to bind)
Alex Grönholm
@agronholm
@dromer bind it on 0.0.0.0 instead?
dreamer
@dromer
hmm. thnx, will give it a try :)
yes, derp. that was it :)
been doing so much automagic stuff lately that I forgot how to bind to public ports ^_^
Alexandre Santos
@alexsantos
I also need to bind the listening port to the OS env $PORT when using Cloud Run.
dreamer
@dromer
any suggestions on cli apps to test fastapi interaction? of course looking into Typer :)
Kamuri Amorim
@kamuridesu
Hello
i'm getting this error:
Traceback (most recent call last):
  File "/home/kamuri/.local/lib/python3.10/site-packages/uvicorn/middleware/debug.py", line 103, in __call__
    await self.app(scope, receive, inner_send)
  File "/home/kamuri/.local/lib/python3.10/site-packages/uvicorn/middleware/asgi2.py", line 20, in __call__
    await instance(receive, send)
TypeError: 'str' object is not callable
any idea on what is happening?
Marcelo Trylesinski
@Kludex
yes, can I see ur uvicorn command and your app file?
3 replies
Sam Ako
@elimence

Hi
I have a many to many relationship modelled in sqlalchemy and I'm having trouble with circular imports in the pydantic schema.
I have a response model for each and would like to return a list of the other in each response

# file a.py
from .b import BInResponse

class AInResponse(BaseModel):
  id: int
  listOfB: Optional[List[BInResponse]]

class AInUpdate(BaseModel):
  id: int
  listOfB: Optional[List[BInResponse]]
# file b.py
from .a import AInResponse

class BInResponse(BaseModel):
  id: int
  listOfA: Optional[List[AInResponse]]

I tried moving the imports to the bottom of the files and using forward refs but that didn't work.
Any suggestions on how to fix this or how I might avoid this in general without having to merge the files ?

dreamer
@dromer
hmm, didn't see a chat for Typer, but anyone here know how you can make an app or command default to --help instead of error?
dreamer
@dromer
ah, found it :)
no_args_is_help=True
ok different quest: how to set -h alias for --help? :)
Rodrigo Leite
@drigols
Good morning, how can I change FastAPI colors in User Interface? For example, title = red...
dreamer
@dromer
of the docs you mean?
Rodrigo Leite
@drigols
was Swagger UI
and redoct