upload_files()/upload_files_async() raises httpx.RequestNotRead

オープン 初心者向け
#136 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
api

調査の方向性

glean/api_client/_hooks/init.py の XGlean.before_request() から始め、次に examples/agent_with_file_upload.py を確認し、ドキュメント化された入力で失敗するアップロードを再現します。upload_files() と upload_files_async() が一覧にあるコンテンツのバリエーションで動作し、非 multipart の JSON エンドポイントに影響がないことが完了の条件です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
20
フォーク
10
平均マージ
1日 6時間
マージ済み PR(30日)
17

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

gleanwork/api-client-python のほかの issue

gleanwork/api-client-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。