Questions tagged [starlette]

Questions about Starlette (a lightweight python ASGI framework/toolkit).

Starlette is a lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services.

https://www.starlette.io

259 questions
0
votes
1 answer

FastAPI OpenAI server side event blocks the main thread

I'm building a FastAPI endpoint which should stream the ChatCompletion of GPT3.5 from the openAI python library. Here is my code : @app.post("/ai_re/") async def read_item(request: Request): base_prompt = "This is a prompt" sources = [] …
0
votes
0 answers

FASTAPI/STARLETTE w/ REDIS Drops responses

I have a very simple FASTAPI app using a websocket route hooked to a busy loop on redis using BRPOP (blocking list pop) from redis. await ws.accept() while True: queue,message = await aioredis_client.brpop(queue_name) ...# some stuff …
Mike
  • 23
  • 4
0
votes
1 answer

TypeError: cannot convert 'URL' object to bytes following AuthLib Google Auth example for FastAPI

I'm trying to implement an example of Google OAuth using Authlib and FastAPI framework, most of the examples I found are using Authlib and that's the recommended approach, so I'm following the Authlib documentation for FastAPI but getting this error…
0
votes
0 answers

Raise fastapi HTTPException not showing full stacktrace to console

I would like to get full stacktrace of exceptions in my log when raising HTTPException, For now I only receive GET /info HTTP/1.1" 400 Bad Request. What Client receives is ok: Bad Request {"detail": "division by zero"}. Im not sure if I should…
mikazz
  • 159
  • 1
  • 11
0
votes
0 answers

Starlette - Simulate file uploads in GraphQL with TestClient

I have a problem testing an application with Starlette's test client. I'm using Ariadne for GraphQL support and I have a resolver that takes two arguments: image and id. Image is an Ariadne Upload type, which in turn is an instance of Starlette's…
Demian
  • 372
  • 1
  • 2
  • 9
0
votes
0 answers

Can I use Gino[starlette] with SQLite?

I'm trying to make the Gino mock, but I keep seeing the error gino.exceptions.UninitializedError: Gino engine is not initialized. My code is formed like this: # __init__.py @functools.lru_cache def get_db_service(): db =…
Plaoo
  • 417
  • 3
  • 19
0
votes
0 answers

FastAPI WebSocket

I have a background process, which does a file preparation after receiving a file on the endpoint. I have a websocket defined also: @app.websocket_route("/ws/{uid}") async def websocket(websocket: WebSocket): await websocket.accept() …
0
votes
0 answers

asyncio.sleep() Gets Cancelled When Awaited Inside Uvicorn With Starlette But Works Normally Otherwise

I have the following code which streams a video file from disk. [Test the code with the python asyncio module in the terminal] python -m asyncio from starlette.applications import Starlette from starlette.responses import StreamingResponse from…
Shakir
  • 270
  • 2
  • 11
0
votes
2 answers

Minimal FastAPI Static File Server Script

I want to write a minimal FastAPI static file server launched from a script that allows you to specify the directory to share on the command line. Following the example in the FastAPI documentation, I wrote this. import uvicorn from fastapi import…
W.P. McNeill
  • 16,336
  • 12
  • 75
  • 111
0
votes
0 answers

RuntimeError: attached to a different loop raises in FastAPI Websocket

There is a websocket endpoint created with FastAPI. When connecting to websocket, this RuntimeError is raised. How can I resolve this error and prevent it from being raised? Version info: fastapi = "0.85.0" starlette = "0.20.4" redis =…
0
votes
0 answers

FastAPI/Starlette get client IP in path operation function

I am trying to access the client IP inside FastAPI path operation function like in the documentation here: https://fastapi.tiangolo.com/advanced/using-request-directly/ from fastapi import FastAPI, Request app =…
juhat
  • 342
  • 2
  • 10
0
votes
0 answers

GraphQL websocket handler not working on Ariadne (object is not callable)

I'm using Uvicorn and Starlette with Ariadne for GraphQL queries, but the GraphQL handler does not seem to be working. I'm using poetry so this is what my pyproject.toml file looks like: [tool.poetry] name = "app-backend" version =…
Demian
  • 372
  • 1
  • 2
  • 9
0
votes
1 answer

How to log user in FastAPI requests

I am trying to log all my FastAPI requests (who requested, what and what is the status code) by creating a custom APIRoute-class. This is my custom Route-class: class LoggingRoute(APIRoute): def get_route_handler(self) -> Callable: …
juhat
  • 342
  • 2
  • 10
0
votes
1 answer

Merge dict header to request.headers.raw

headers.raw is typing.List[typing.Tuple[bytes, bytes]] I want to merge it into another dict, like the one below: client.build_request(headers=dict(request.headers.raw) | {"foo": "bar"}), However I got the error expected "Union[Headers, Dict[str,…
Rodrigo
  • 135
  • 4
  • 45
  • 107
0
votes
0 answers

FastAPI middleware to substitute X-Forwarded-Uri and X-Forwarded-Host

I'm new with FastAPI and Starlette, and I'm struggling to make a middleware that tampers the incoming request. I'm trying to parse the X-Forwarded-Uri and the X-Forwarded-Host headers and modify the incoming request so that those are taken into…