From 2de6b44f7a77dcdef97d425fac42018d36429a35 Mon Sep 17 00:00:00 2001 From: Nathalie Jonathan Date: Wed, 27 Nov 2024 13:48:03 -0800 Subject: [PATCH] Prevent AIOHttpConnection from encoding the url a second time. Signed-off-by: Nathalie Jonathan --- opensearchpy/connection/http_async.py | 4 +++- test_opensearchpy/test_async/test_http_connection.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/opensearchpy/connection/http_async.py b/opensearchpy/connection/http_async.py index 9add4785..7fb69093 100644 --- a/opensearchpy/connection/http_async.py +++ b/opensearchpy/connection/http_async.py @@ -15,6 +15,8 @@ import warnings from typing import Any, Collection, Mapping, Optional, Union +import yarl + from .._async._extra_imports import aiohttp, aiohttp_exceptions # type: ignore from .._async.compat import get_running_loop from .._async.http_aiohttp import AIOHttpConnection @@ -210,7 +212,7 @@ async def perform_request( try: async with self.session.request( method, - url, + yarl.URL(url, encoded=True), data=body, auth=auth, headers=req_headers, diff --git a/test_opensearchpy/test_async/test_http_connection.py b/test_opensearchpy/test_async/test_http_connection.py index 34c729e0..8568a6f8 100644 --- a/test_opensearchpy/test_async/test_http_connection.py +++ b/test_opensearchpy/test_async/test_http_connection.py @@ -29,6 +29,7 @@ from unittest import mock import pytest +import yarl from multidict import CIMultiDict from opensearchpy._async._extra_imports import aiohttp # type: ignore @@ -91,7 +92,7 @@ async def test_basicauth_in_request_session(self, mock_request: Any) -> None: await c.perform_request("post", "/test") mock_request.assert_called_with( "post", - "http://localhost:9200/test", + yarl.URL("http://localhost:9200/test", encoded=True), data=None, auth=c._http_auth, headers={}, @@ -120,7 +121,7 @@ def auth_fn(*args: Any, **kwargs: Any) -> Any: mock_request.assert_called_with( "post", - "http://localhost:9200/test", + yarl.URL("http://localhost:9200/test", encoded=True), data=None, auth=None, headers={