Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

APIConnectionError raised when using AsyncOpenAI along FastAPI and uvicorn(uvloop)

Aperta
#1,927 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@LuminaX-alt ci sta già lavorando.

Dal 4/8/2025.

  • #41 di @LuminaX-alt — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
fastapi, python
Ambito
api, backend

Direzione di ricerca

Inizia con le combinazioni delle dipendenze in pyproject.toml e l'esempio main.py, quindi riproduci la richiesta /test con Python 3.11 con uvloop abilitato e disabilitato. Confronta il traceback risultante e determina se il problema si trova nella libreria o nell'integrazione del ciclo di eventi; il lavoro è completato quando sono state identificate una causa riproducibile e una soluzione verificata per le versioni elencate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug sdk
Confirm this is an issue with the Python library and not an underlying OpenAI API
  • This is an issue with the Python library
Describe the bug

Exception raised when using AsyncOpenAI with FastAPI and uvicorn issue seems to be compability issues with uvloop that is added through the extras = ["standard"].

fastapi = "0.115.6"
uvicorn = {extras = ["standard"], version = "0.32.1"}
openai = "^1.54.4"

Installing dependencies manually and leaving out uvloop works.

fastapi = "0.115.6"
uvicorn = "0.32.1"
# from extras = ["standard"]
websockets="14.1"
watchfiles="1.0.0"
pyyaml="6.0.2"
python-dotenv="1.0.1"
httptools="0.6.4"
# uvloop="0.21.0" leads to openAI async exception
To Reproduce
  1. pyproject.toml with poetry dep.
    [tool.poetry.dependencies]
    python = ">=3.11,<3.12"
    fastapi = "0.115.6"
    uvicorn = {extras = ["standard"], version = "0.32.1"}
    openai = "^1.54.4"

  2. Run app main.py.

  3. Call endpoint
    http://localhost:50051/test

Exception:
File "/Users/badrelfarri/Documents/Code/RevVue/simple-async-openai-assistant/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 1610, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.

Code snippets
main.py


from fastapi import FastAPI
import uvicorn
from openai import AsyncOpenAI

apiKey = ""
app = FastAPI()

@app.get("/test")
async def test():
    systemMessage = "Get a title for the conversation, the title shall not have more than 4 words"
    messages = [
        {"role": "system", "content": systemMessage},
        {
            "role": "user",
            "content": "Is the earth flat",
        },
    ]
    result = await AsyncOpenAI(api_key=apiKey, timeout=30).chat.completions.create(
        model="gpt-4o-mini",
        messages=messages,
    )
    title = result.choices[0].message.content
    return title

if __name__ == '__main__':
    uvicorn.run(app, host="0.0.0.0", port=50051)
OS

macOS

Python version

Python 3.11.4

Library version

openai v1.54.4

Lingua principale
Python
Stelle
31.8k
Fork
8k
Merge medio
1g 1h
PR unite (30g)
137

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/openai-python

Tutte le issue di openai/openai-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.