gleanwork / gleanwork/api-client-python
upload_files()/upload_files_async() raises httpx.RequestNotRead
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20
- Forks
- 10
- Ø Merge
- 1 T. 6 Std.
- Gemergte PRs (30 T.)
- 17
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in glean/api_client/_hooks/init.py bei XGlean.before_request(), sieh dir anschließend examples/agent_with_file_upload.py an und reproduziere den fehlschlagenden Upload mit den dokumentierten Eingaben. Erledigt ist die Aufgabe, wenn upload_files() und upload_files_async() für die aufgeführten Inhaltsvarianten funktionieren, während nicht-multipart JSON-Endpunkte weiterhin unbeeinträchtigt bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 78/100