gleanwork / gleanwork/api-client-python
upload_files()/upload_files_async() raises httpx.RequestNotRead
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 20
- Forks
- 10
- Merge médio
- 1d 6h
- PRs com merge (30d)
- 17
Descrição
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.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em glean/api_client/_hooks/init.py, em XGlean.before_request(), depois revise examples/agent_with_file_upload.py e reproduza o upload que está falhando com as entradas documentadas. Está concluído quando upload_files() e upload_files_async() funcionarem para as variantes de conteúdo listadas, enquanto os endpoints JSON não multipart permanecerem inalterados.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- api
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Pouca atividade
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 78/100