gleanwork / gleanwork/api-client-python

upload_files()/upload_files_async() raises httpx.RequestNotRead

Đang mở Phù hợp với người mới
#136 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

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

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

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.

Đánh giá

Công nghệ
python
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
78/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.