Skip to content

The size of the request headers is too long #39605

Closed as not planned
Closed as not planned
@cmilanes93

Description

@cmilanes93
  • Azure Cosmos: 4.9.0
  • Python Version: 3.11.9

Describe the bug
Im encountering an HTTP 400 error indicating that the request headers are too large when using the Azure Cosmos DB Python SDK.

To Reproduce
Steps to reproduce the behavior:

  1. import logging
    import time
    import json
    import pandas as pd
    from azure.identity import DefaultAzureCredential
    from azure.cosmos import CosmosClient

logging.basicConfig(level=logging.INFO)

Conexión a Cosmos DB

COSMOS_ENDPOINT = "#####"
DATABASE_NAME = "####"
CONTAINER_NAME = "####"

credential = DefaultAzureCredential()
client = CosmosClient(COSMOS_ENDPOINT, credential=credential)

database = client.get_database_client(DATABASE_NAME)
container = database.get_container_client(CONTAINER_NAME)

Partición (en este caso solo hay una)

PARTITION_KEY_VALUE = "###"

Diccionario para guardar métricas y SQL de cada consulta

metricas_consultas = {}

def ejecutar_consulta(sql_query, parameters=None, partition_key=None,
consulta_nombre="consulta_sin_nombre", descripcion=""):
"""
Ejecuta una consulta en Cosmos DB, mide el tiempo y guarda resultados en metricas_consultas.
"""
start_time = time.time()
# Ejecución de la consulta
results_iter = container.query_items(
query=sql_query,
parameters=parameters or [],
partition_key=partition_key
# NOTA: No se usa enable_cross_partition_query porque se tiene una sola partición.
)
results_list = list(results_iter)
elapsed = time.time() - start_time

# Guardar métricas
metricas_consultas[consulta_nombre] = {
    "pregunta": descripcion,
    "sql_query": sql_query,
    "tiempo_seg": round(elapsed, 4),
    "num_documentos": len(results_list)
}

logging.info(f"[{consulta_nombre}] -> {len(results_list)} resultados en {elapsed:.4f} seg")
return results_list

Query:
consulta_nombre = "group_by_factor_riesgo"
descripcion = "Agrupa (FACTOR_DE_RIESGO, TIPO_RIESGO) sin filtros"

sql_query = """
SELECT
c.I_GRAVEDAD,
c.I_PROBABILIDAD,
COUNT(1)
FROM c
GROUP BY c.I_GRAVEDAD, c.I_PROBABILIDAD
"""

results = ejecutar_consulta(
sql_query=sql_query,
partition_key=PARTITION_KEY_VALUE,
consulta_nombre=consulta_nombre,
descripcion=descripcion
)

for r in results:
print(r)

Expected behavior
Output 16 results.

Screenshots

Image

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.CosmosService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-author-feedbackWorkflow: More information is needed from author to address the issue.no-recent-activityThere has been no recent activity on this issue.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions