upload_files()/upload_files_async() raises httpx.RequestNotRead

Aperta Adatta ai principianti
#136 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia in glean/api_client/_hooks/init.py, in XGlean.before_request(), poi esamina examples/agent_with_file_upload.py e riproduci l'upload che fallisce con gli input documentati. Il lavoro è completato quando upload_files() e upload_files_async() funzionano per le varianti di contenuto elencate, mentre gli endpoint JSON non-multipart rimangono inalterati.

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

Descrizione

Description
The official example examples/agent_with_file_upload.py fails with httpx.RequestNotRead when calling glean.client.chat.upload_files().

Steps to reproduce
Run the official example as-is:

from glean.api_client import Glean, models
with Glean(api_token="...", instance="...") as glean:
upload_result = glean.client.chat.upload_files(
files=[models.File(file_name="test.csv", content=b"a,b\n1,2")]
)
All content variants produce the same error: bytes, io.BytesIO, open(..., 'rb'), FileTypedDict.

Error
httpx.RequestNotRead: Attempted to access streaming request content, without having called read().

Root cause
The XGlean BeforeRequestHook always reconstructs the httpx.Request object to add optional headers:

glean/api_client/_hooks/init.py — XGlean.before_request()

return httpx.Request(
method=request.method,
url=request.url,
headers=new_headers,
content=request.content, # <-- raises RequestNotRead
extensions=request.extensions,
)
For multipart requests (file uploads), httpx builds the body as a stream. Accessing request.content before request.read() raises httpx.RequestNotRead. This happens on every upload_files() / upload_files_async() call, regardless of how file content is passed, because the hook runs before the request is sent.

Non-multipart endpoints (JSON body) are unaffected because request.content is available immediately.

Lingua principale
Python
Stelle
20
Fork
10
Merge medio
1g 6h
PR unite (30g)
17

Guida per i contributori

Apri la guida per i contributori

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 gleanwork/api-client-python

Tutte le issue di gleanwork/api-client-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.