Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:06
    github-actions[bot] commented #2411
  • 01:04
    codecov[bot] commented #2411
  • 01:04
    codecov[bot] commented #2411
  • 01:02
    codecov[bot] commented #2411
  • 01:02
    codecov[bot] commented #2411
  • 01:02
    maoyibo synchronize #2411
  • 00:54
    github-actions[bot] commented #2410
  • 00:52
    codecov[bot] commented #2410
  • 00:51
    codecov[bot] commented #2410
  • 00:50
    codecov[bot] commented #2410
  • 00:50
    codecov[bot] commented #2410
  • 00:50
    maoyibo synchronize #2410
  • 00:35
    codecov[bot] commented #2410
  • 00:35
    codecov[bot] commented #2410
  • 00:35
    maoyibo synchronize #2410
  • 00:33
    codecov[bot] commented #2410
  • 00:33
    codecov[bot] commented #2410
  • 00:33
    maoyibo synchronize #2410
  • Nov 25 23:47
    Mause commented #2417
  • Nov 25 22:50
    liamklaus commented #2417
NomeChomsky
@NomeChomsky
ValueError: [TypeError("'ObjectId' object is not iterable"), TypeError('vars() argument must have dict attribute')]
Matt Nuzzaco
@nuzz
is there a good example of using postgres's jsonb in conjunction with a fastapi model?
I have a model with fields one of which is a config field submodel, this submodel I want to store as a jsonb column.
Thiago
@braindata_company_gitlab
My FoerignKeyField using tortoise-orm, not appearing on swagger
i cant relation my class with other
how can i do this ?
Thiago
@braindata_company_gitlab
anyone ???
rahul
@rahulkamail
@braindata_company_gitlab , can you provide your code so that we can check it ?
NullSense
@NullSense
I am trying to implement JWT auth on an endpoint, without any user accounts. This means a JWT token will be communicated with the client. However, I am unable to get it working. Maybe someone has an idea?
class Data(BaseModel):
    id: UUID
    time: datetime
    ...

def decode_token(token: dict) -> Dict[str, Any]:
    try:
        payload = jwt.decode(
            token, CONFIG["jwt"]["secret_key"], algorithms=CONFIG["jwt"]["algorithm"]
        )
        data: dict = payload.get("data")
        if data is None:
            raise invalid_data
    except JWTError:
        raise credentials_exception from JWTError
    else:
        return data


@router.post("/data/request_data/")
async def data(data: Data = Depends(decode_token), app: Application = Depends()) -> None:
    app.request_data(data)
And my test looks like this:
def test_data(client, data_specs):
        data = {"data": data_specs}
        token = jwt.encode(data, CONFIG["jwt"]["secret_key"], algorithm=CONFIG["jwt"]["algorithm"])

        response = client.post("/v1/data/request_data/", token)

>       assert response.status_code == 200
E       assert 422 == 200
E        +  where 422 = <Response [422]>.status_code
karthikganesh16
@karthikganesh16
Team, when I add a middleware to my fastapi app, i end up with TypeError: 'NoneType' object is not callable related to URL hit for favicon.ico. As mine is a backend API don't want this second hit to happen and fail. Your pointers will help. Note: I don't see any issue/second hit when I don't have any middleware. Thanks.
Akshay Verma
@aeroaks
Hi, I am using FastAPI to handle POST request from a server and then handle the information in BackgroundTasks.
I am getting this behaviour where the server is sending 10-15 requests within a minute and 1 request is not handled. The server retries to send the request and after few attempts disables the connection. I am using Gunicorn with 5 workers. What else can I do to improve the request handling?
Ahtisham Shafi
@Ahtii
anyone please help me here: tiangolo/fastapi#2403
mdgilene
@mdgilene

Hey guys, need some help with very strange issue I'm encountering. Here's the situation:

Service A: (FastAPI/Uvicorn/Gunicorn)
Service B: (FastAPI/Uviconr/Gunicorn)

Service A needs to upload a large file (~1Gb) to Service B, Service B processes the file.

However, upon initiating the upload, Service B encounters a Critical Worker Timeout before even entering the route handler (From what I can tell based on log messages. Critical worker timeouts in Gunicorn provide no stack trace or debug info). I have tried making this request from Service A using both HTTPX and Requests but neither seem to make any difference.

Strange thing is, if I attempt to perform the same request to Service B but just from the command line using CURL, the requests works fine.

I'm really at a loss for what might be going on here. Anyone have any thoughts?

Gilberto Corrêa de Souza
@gilberto.souza_gitlab
unfortunately I had an error similar to this, the solution I found was to greatly increase the timeout time of the gunicorn
mdgilene
@mdgilene
I guess that is A solution...but definitely not one I would be happy with
Doesn't really address the issue. Just hides it.
Gilberto Corrêa de Souza
@gilberto.souza_gitlab
yes, just hide it, but in the issues of the gunicorn said something about treating this type of case
if you find another solution, i would be very happy to use it :)
mdgilene
@mdgilene
My only theory currently is that the low level transports used by HTTPX and Requests are sending the file so slowly (in such small chunks) that Gunicorn gives up on the request. CURL uploads the whole file pretty fast honestly, but HTTPX and Requests sit around for quite a number of minutes trying to upload the file.
Gilberto Corrêa de Souza
@gilberto.souza_gitlab
yes, it makes sense, in the documentation of the gunicorn itself says something about how to configure the timeout according to the application use case
mdgilene
@mdgilene
The thing is I am using an Async worker (Uvicorn) and I have made sure that once the request is inside my route handler any potentially long blocking tasks are wrapped up and made asyncronous. So none of my code should be causing the worker to time out. The timeout occurs before even hitting my code. Also like I said, this works perfectly fine when upload the file via CURL. Just not from another service using HTTPX or requets.
Gilberto Corrêa de Souza
@gilberto.souza_gitlab
yes, in my case too, i'm using websocket and gunicorn closed connections without warning
Ahtisham Shafi
@Ahtii
@gilberto.souza_gitlab @mdgilene please help me with this problem tiangolo/fastapi#2403
mdgilene
@mdgilene
Idk much about websockets. But does receieve_bytes actually return a file_like object? Or just bytes. If it's just bytes there should be any reason to open it since you already have the binary content in memory
Gilberto Corrêa de Souza
@gilberto.souza_gitlab
yes, looking quickly you are not treating the bytes so that it can be processed as the file you sent
epifanio
@epifanio

Hi, I am trying to learn .. I got confudsed in building a get/post api, I wrote this:


class baskettable(BaseModel):
    data: dict = pydantic.Field(default={"":""}, 
                                example={"b22d6caa-aff5-569c-b0db-222b3c3d617d":{"title":"SYNOP data from station VANGSNES", 
                                "feature_type":"timeSeries", 
                                "resources":{"opendap":["https://thredds.met.no/thredds/dodsC/arcticdata/obsSynop/01338"]}}, 
                                "1212c409-f2ea-5f71-a276-dba7d142e5e7":{"title":"SYNOP data from station VANGSNES", 
                                "feature_type":"timeSeries", 
                                "resources":{"opendap":["https:\\thredds.met.no/thredds/dodsC/arcticdata/obsSynop/01338"]}}})
    email: str = pydantic.Field(default='me@you.web', example='me@you.web')
    project: str = pydantic.Field(default='METSIS', example='METSIS')


@app.get("/get_baskettable")
async def getdict(data: baskettable):
    return data

@app.post("/post_baskettable")
async def postdict(data: baskettable):
    return data

I got the post method to work .. but the get does not ..
this works fine:

curl -X POST "https://pybasket.epinux.com/post_baskettable" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"data\":{\"b22d6caa-aff5-569c-b0db-222b3c3d617d\":{\"title\":\"SYNOP data from station VANGSNES\",\"feature_type\":\"timeSeries\",\"resources\":{\"opendap\":[\"https://thredds.met.no/thredds/dodsC/arcticdata/obsSynop/01338\"]}},\"1212c409-f2ea-5f71-a276-dba7d142e5e7\":{\"title\":\"SYNOP data from station VANGSNES\",\"feature_type\":\"timeSeries\",\"resources\":{\"opendap\":[\"https:\\\\thredds.met.no/thredds/dodsC/arcticdata/obsSynop/01338\"]}}},\"email\":\"me@you.web\",\"project\":\"METSIS\"}"

while this:

curl -X GET "https://pybasket.epinux.com/get_baskettable" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"data\":{\"b22d6caa-aff5-569c-b0db-222b3c3d617d\":{\"title\":\"SYNOP data from station VANGSNES\",\"feature_type\":\"timeSeries\",\"resources\":{\"opendap\":[\"https://thredds.met.no/thredds/dodsC/arcticdata/obsSynop/01338\"]}},\"1212c409-f2ea-5f71-a276-dba7d142e5e7\":{\"title\":\"SYNOP data from station VANGSNES\",\"feature_type\":\"timeSeries\",\"resources\":{\"opendap\":[\"https:\\\\thredds.met.no/thredds/dodsC/arcticdata/obsSynop/01338\"]}}},\"email\":\"me@you.web\",\"project\":\"METSIS\"}"

returns the error:

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

What I am doing wrong? I am probably missing some basic web development concept :(

mdgilene
@mdgilene
Yeah. GET requests cannot have a body. Like the error message says
epifanio
@epifanio
@mdgilene I was trtying to understand that, I am actually in trouble understanding thew meaning
mdgilene
@mdgilene
GET requests ask the server for data that is returned in the response body. So your server should lookup the data from a database or somewhere and return it.
epifanio
@epifanio
means a get doesn't require a input?
mdgilene
@mdgilene
POST requests send data to the server
The only input GET requests can have is in the form of URL parameters (/user/{id}) or query parameters (/users?id=foo)
epifanio
@epifanio
I see, ok makes absolutely sense, so to develop something that returns data baesd on some conditions in the request .. I will need to use the query syntax and not a simple "GET" with a datamodel
thank you!
Gilberto Corrêa de Souza
@gilberto.souza_gitlab
epifanio
@epifanio
@mdgilene in a Query symtax can I resue the custom datamodel built with pedantic?
mdgilene
@mdgilene
Uhh, Kind of? I guess it's possible. But probably not the best way to handle it. You can theortically have a query /user?query="{"id":"1"}" where you include a full JSON string. Then decode it into your data model. But like I said, there are better ways to handle this IMO
epifanio
@epifanio
something like:
async def getdict(request: Request,
                    data: baskettable = Query(None,
                                     title="dict of datasourcese",
                                     description="dict of datasources  and meta informations")):
mdgilene
@mdgilene
Idk how if it works out of the box with FastAPI though. You might need to capture it as a string then decode manually in your route handler. Haven't tried so idk
epifanio
@epifanio
@mdgilene what would be a better approoach instread of doing " /user?query="{"id":"1"}" " ?
Ahtisham Shafi
@Ahtii
@mdgilene I think receieve_bytes return bytes not sure and I am trying to store the file on local file storage on the server side.
@gilberto.souza_gitlab thanks a lot man will look at it.
Gilberto Corrêa de Souza
@gilberto.souza_gitlab
any time
matrixbot
@matrixbot
thiras hello. It seems SQLAlchemy has full async support at 1.4 version. Is there any plan to update the docs (and take the advantage of SA's ORM instead of encore's databases)?
Daniel
@danieljfarrell
@thiras I just followed the link. It seems version 1.4 is almost like the a release candidate for 2.0, there are lots of good modernisations. However, there is a note mentioning that asyncio support should be considered alpha because they have added a new AsyncEngine object. Personally I would not use in production just yet.
Deniz Saner
@denizs
Hey there - does anyone know how to link other endpoints in OpenApi descriptions? For instance stating that some header for endpoint 2 must be set to the response of endpoint 1?
Nicolas Gilles
@ngilles
@danieljfarrell I have to say I haven't used it (I've been using "raw" asyncpg so far) but I saw that there is gino that as far as I understand use bits from SQLAlchemy but has it's own execution engine over asyncpg
looks like a migration path from gino to an async-native SQLAlchemy shouldn't be too hard...