upload_files()/upload_files_async() raises httpx.RequestNotRead
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu trong glean/api_client/_hooks/init.py tại XGlean.before_request(), sau đó xem xét examples/agent_with_file_upload.py và tái hiện lần upload bị lỗi bằng các đầu vào được ghi trong tài liệu. Hoàn tất có nghĩa là upload_files() và upload_files_async() hoạt động với các biến thể nội dung được liệt kê, trong khi các endpoint JSON không phải multipart vẫn không bị ảnh hưởng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 20
- Fork
- 10
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 17
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của gleanwork/api-client-python
-
Issue Obtaining Agent Schema Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
gleanwork/api-client-python#137 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
gleanwork/api-client-python#133 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
gleanwork/api-client-python#115 · 4 bình luận ·
-
Model serialization drops keys Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
gleanwork/api-client-python#105 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
gleanwork/api-client-python#57 · 2 bình luận ·
Tất cả issue của gleanwork/api-client-python
Issue tương tự
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100