From d2bb1af1c1141ad43708cfb06fcc13f06087d9d4 Mon Sep 17 00:00:00 2001 From: Josef Kudera <46950237+kudj@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:28:43 +0200 Subject: [PATCH 1/2] SUPPORT-8272 fix query string when contains more params --- python-sync-actions/src/http_generic/auth.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-sync-actions/src/http_generic/auth.py b/python-sync-actions/src/http_generic/auth.py index d0efaa5..733d6d4 100644 --- a/python-sync-actions/src/http_generic/auth.py +++ b/python-sync-actions/src/http_generic/auth.py @@ -167,7 +167,10 @@ def __call__(self, r): r.headers[self.key] = f"{self.token}" elif self.position == 'query': - r.url = f"{r.url}?{urlencode({self.key: self.token})}" + if '?' in r.url: + r.url = f"{r.url}&{urlencode({self.key: self.token})}" + else: + r.url = f"{r.url}?{urlencode({self.key: self.token})}" else: raise AuthBuilderError(f"Unsupported position {self.position} for API Key auth method") return r From 366d830d324903e85490553e1990fcd6fcaa7fb6 Mon Sep 17 00:00:00 2001 From: Josef Kudera <46950237+kudj@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:00:45 +0200 Subject: [PATCH 2/2] review - using urlparse --- python-sync-actions/src/http_generic/auth.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/python-sync-actions/src/http_generic/auth.py b/python-sync-actions/src/http_generic/auth.py index 733d6d4..8cc990c 100644 --- a/python-sync-actions/src/http_generic/auth.py +++ b/python-sync-actions/src/http_generic/auth.py @@ -3,7 +3,7 @@ import re from abc import ABC, abstractmethod from typing import Callable, Union, Dict, Literal -from urllib.parse import urlencode +from urllib.parse import urlparse, parse_qs, urlencode, urlunparse import requests from requests import auth @@ -167,10 +167,12 @@ def __call__(self, r): r.headers[self.key] = f"{self.token}" elif self.position == 'query': - if '?' in r.url: - r.url = f"{r.url}&{urlencode({self.key: self.token})}" - else: - r.url = f"{r.url}?{urlencode({self.key: self.token})}" + parsed_url = urlparse(r.url) + query_params = parse_qs(parsed_url.query) + query_params.update({self.key: self.token}) + new_query = urlencode(query_params, doseq=True) + r.url = urlunparse(parsed_url._replace(query=new_query)) + else: raise AuthBuilderError(f"Unsupported position {self.position} for API Key auth method") return r