upload_files()/upload_files_async() raises httpx.RequestNotRead
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in glean/api_client/_hooks/init.py at XGlean.before_request(), then review examples/agent_with_file_upload.py and reproduce the failing upload with the documented inputs. Done means upload_files() and upload_files_async() work for the listed content variants while non-multipart JSON endpoints remain unaffected.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 20
- Forks
- 10
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 17
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gleanwork/api-client-python
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
gleanwork/api-client-python#137 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
gleanwork/api-client-python#133 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
gleanwork/api-client-python#115 · 4 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
gleanwork/api-client-python#105 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
gleanwork/api-client-python#57 · 2 comments ·
All issues in gleanwork/api-client-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100