From 1b3333eb7f0f71c18c323f9be16d15494e3f0a8c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 Apr 2026 12:25:15 +0200 Subject: [PATCH 1/7] add schema earlier --- ayon_api/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ayon_api/utils.py b/ayon_api/utils.py index 7294c110b..2cf8a5794 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -759,6 +759,11 @@ def validate_url( # Not sure if this is good idea? modified_url = stripperd_url.rstrip("/") + + # Make sure url has http schema + if not modified_url.lower().startswith("http"): + modified_url = f"http://{modified_url}" + parsed_url = _try_parse_url(modified_url) universal_hints = [ "does the url work in browser?" From 6c9dd8357ac7c3040c17e1fce6fda5354bad2d77 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 Apr 2026 12:25:39 +0200 Subject: [PATCH 2/7] don't use full path just netloc on first attempt --- ayon_api/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ayon_api/utils.py b/ayon_api/utils.py index 2cf8a5794..cebde7d5e 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -777,11 +777,10 @@ def validate_url( hints=universal_hints ) - # Try add 'https://' scheme if is missing - # - this will trigger UrlError if both will crash - if not parsed_url.scheme: + if parsed_url.path: + tmp_url = f"{parsed_url.scheme}://{parsed_url.netloc}" new_url = _try_connect_to_server( - "http://" + modified_url, + tmp_url, timeout=timeout, verify=verify, cert=cert, From 94e03870216c009980163c94bcadc6549dfa60e8 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 Apr 2026 12:25:54 +0200 Subject: [PATCH 3/7] modified hint --- ayon_api/utils.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ayon_api/utils.py b/ayon_api/utils.py index cebde7d5e..892f73e8a 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -798,14 +798,9 @@ def validate_url( return new_url hints = [] - if "/" in parsed_url.path or not parsed_url.scheme: - new_path = parsed_url.path.split("/")[0] - if not parsed_url.scheme: - new_path = "https://" + new_path - - hints.append( - "did you mean \"{}\"?".format(parsed_url.scheme + new_path) - ) + if parsed_url.path: + new_path = f"{parsed_url.scheme}{parsed_url.netloc}" + hints.append(f"did you mean \"{new_path}\"?") raise UrlError( "Couldn't connect to server on \"{}\"".format(url), From 60ff60acd193ce468b21a1433bd0f258fc489940 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 Apr 2026 13:40:57 +0200 Subject: [PATCH 4/7] use api info for server validation --- ayon_api/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ayon_api/utils.py b/ayon_api/utils.py index 892f73e8a..97c977a8d 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -570,11 +570,12 @@ def _try_connect_to_server( # TODO add validation if the url lead to AYON server # - this won't validate if the url lead to 'google.com' response = requests.get( - url, + f"{url}/api/info", timeout=timeout, verify=verify, cert=cert, ) + _ = response.json() if response.history: return response.history[-1].headers["location"].rstrip("/") return url @@ -770,8 +771,9 @@ def validate_url( ] if parsed_url is None: raise UrlError( - "Invalid url format. Url cannot be parsed as url \"{}\".".format( - modified_url + ( + "Invalid url format. Url cannot be parsed" + f" as url \"{modified_url}\"." ), title="Invalid url format", hints=universal_hints From e8681fb91dbe85de00ee20d0adaa0ffdd3b26471 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 4 May 2026 17:04:50 +0200 Subject: [PATCH 5/7] fix typo --- ayon_api/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ayon_api/utils.py b/ayon_api/utils.py index 97c977a8d..91a8a596b 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -761,7 +761,7 @@ def validate_url( # Not sure if this is good idea? modified_url = stripperd_url.rstrip("/") - # Make sure url has http schema + # Make sure url has http scheme if not modified_url.lower().startswith("http"): modified_url = f"http://{modified_url}" From 3fb48a878238f23ace6296a300746b5239d22831 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 4 May 2026 17:05:10 +0200 Subject: [PATCH 6/7] use one variable for pathless url --- ayon_api/utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ayon_api/utils.py b/ayon_api/utils.py index 91a8a596b..88ea037a3 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -779,10 +779,9 @@ def validate_url( hints=universal_hints ) + pathless_url = f"{parsed_url.scheme}://{parsed_url.netloc}" if parsed_url.path: - tmp_url = f"{parsed_url.scheme}://{parsed_url.netloc}" new_url = _try_connect_to_server( - tmp_url, timeout=timeout, verify=verify, cert=cert, @@ -801,8 +800,7 @@ def validate_url( hints = [] if parsed_url.path: - new_path = f"{parsed_url.scheme}{parsed_url.netloc}" - hints.append(f"did you mean \"{new_path}\"?") + hints.append(f"did you mean \"{pathless_url}\"?") raise UrlError( "Couldn't connect to server on \"{}\"".format(url), From 8f7b4955791bbe8aaeed97f9e2f78384431e5d65 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 4 May 2026 17:14:42 +0200 Subject: [PATCH 7/7] add 'UrlNotReached' to be raised for connection error --- ayon_api/exceptions.py | 16 ++++++++++++++-- ayon_api/utils.py | 6 ++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ayon_api/exceptions.py b/ayon_api/exceptions.py index 6a44e9d9c..c72beb915 100644 --- a/ayon_api/exceptions.py +++ b/ayon_api/exceptions.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import copy try: @@ -21,13 +23,23 @@ class UrlError(Exception): UI if needed. """ - def __init__(self, message, title, hints=None): + + def __init__( + self, + message: str, + title: str, + hints: list[str] | None = None, + ) -> None: if hints is None: hints = [] self.title = title self.hints = hints - super(UrlError, self).__init__(message) + super().__init__(message) + + +class UrlNotReached(UrlError): + pass class ServerError(Exception): diff --git a/ayon_api/utils.py b/ayon_api/utils.py index 88ea037a3..cd3a9a71a 100644 --- a/ayon_api/utils.py +++ b/ayon_api/utils.py @@ -27,6 +27,7 @@ ) from .exceptions import ( UrlError, + UrlNotReached, ServerError, UnauthorizedError, HTTPRequestError, @@ -782,6 +783,7 @@ def validate_url( pathless_url = f"{parsed_url.scheme}://{parsed_url.netloc}" if parsed_url.path: new_url = _try_connect_to_server( + pathless_url, timeout=timeout, verify=verify, cert=cert, @@ -802,8 +804,8 @@ def validate_url( if parsed_url.path: hints.append(f"did you mean \"{pathless_url}\"?") - raise UrlError( - "Couldn't connect to server on \"{}\"".format(url), + raise UrlNotReached( + f"Couldn't connect to server on \"{url}\"", title="Couldn't connect to server", hints=hints + universal_hints )