From 3037f25eb1189f342bcc404625eaac651f06e591 Mon Sep 17 00:00:00 2001 From: Anil Sahoo Date: Mon, 24 Mar 2025 11:45:51 +0530 Subject: [PATCH 1/4] Fixed an issue where the upgrade_check API returned an unexpected keyword argument 'cafile' due to changes in the urllib package supporting Python v3.13. #8577 --- web/pgadmin/misc/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/web/pgadmin/misc/__init__.py b/web/pgadmin/misc/__init__.py index 4d19e182423..9bff7e6d407 100644 --- a/web/pgadmin/misc/__init__.py +++ b/web/pgadmin/misc/__init__.py @@ -29,6 +29,8 @@ import time import json import os +import sys +import ssl from urllib.request import urlopen from pgadmin.settings import get_setting, store_setting @@ -324,6 +326,16 @@ def validate_binary_path(): return make_json_response(data=gettext(version_str), status=200) +def urlopen_with_ssl(url, data, timeout, cafile): + context = ssl.create_default_context(cafile=cafile) + if sys.version_info >= (3, 13): + # Use SSL context for Python 3.13+ + return urlopen(url, data=data, timeout=timeout, context=context) + else: + # Use cafile parameter for older versions + return urlopen(url, data=data, timeout=timeout, cafile=cafile) + + @blueprint.route("/upgrade_check", endpoint="upgrade_check", methods=['GET']) @pga_login_required @@ -346,7 +358,8 @@ def upgrade_check(): # It stuck on rendering the browser.html, while working in the # broken network. if os.path.exists(config.CA_FILE): - response = urlopen(url, data, 5, cafile=config.CA_FILE) + response = urlopen_with_ssl( + url, data, 5, config.CA_FILE) else: response = urlopen(url, data, 5) current_app.logger.debug( From 1853d14b222d008e68067d5d2967e478e9a2c2c3 Mon Sep 17 00:00:00 2001 From: Anil Sahoo Date: Mon, 24 Mar 2025 18:48:01 +0530 Subject: [PATCH 2/4] Optimized the code to not use the urlopen_with_ssl function --- web/pgadmin/misc/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/pgadmin/misc/__init__.py b/web/pgadmin/misc/__init__.py index 9bff7e6d407..1628216a6a9 100644 --- a/web/pgadmin/misc/__init__.py +++ b/web/pgadmin/misc/__init__.py @@ -357,9 +357,16 @@ def upgrade_check(): # Do not wait for more than 5 seconds. # It stuck on rendering the browser.html, while working in the # broken network. - if os.path.exists(config.CA_FILE): - response = urlopen_with_ssl( - url, data, 5, config.CA_FILE) + if os.path.exists(config.CA_FILE) and sys.version_info >= ( + 3, 13): + # Use SSL context for Python 3.13+ + context = ssl.create_default_context(cafile=config.CA_FILE) + response = urlopen(url, data=data, timeout=5, + context=context) + elif os.path.exists(config.CA_FILE): + # Use cafile parameter for older versions + response = urlopen(url, data=data, timeout=5, + cafile=config.CA_FILE) else: response = urlopen(url, data, 5) current_app.logger.debug( From dfaca6954e7a2d5d2a53f61f5ed9797c767af3bc Mon Sep 17 00:00:00 2001 From: Anil Sahoo Date: Mon, 24 Mar 2025 18:51:07 +0530 Subject: [PATCH 3/4] Fixed pep8 issues --- web/pgadmin/misc/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/pgadmin/misc/__init__.py b/web/pgadmin/misc/__init__.py index 1628216a6a9..7b395a53267 100644 --- a/web/pgadmin/misc/__init__.py +++ b/web/pgadmin/misc/__init__.py @@ -358,7 +358,7 @@ def upgrade_check(): # It stuck on rendering the browser.html, while working in the # broken network. if os.path.exists(config.CA_FILE) and sys.version_info >= ( - 3, 13): + 3, 13): # Use SSL context for Python 3.13+ context = ssl.create_default_context(cafile=config.CA_FILE) response = urlopen(url, data=data, timeout=5, From 3c5e9f4dbc0efb244821b1f80efe980fd6483aac Mon Sep 17 00:00:00 2001 From: Anil Sahoo Date: Tue, 25 Mar 2025 09:37:51 +0530 Subject: [PATCH 4/4] urlopen_with_ssl function removed --- web/pgadmin/misc/__init__.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/web/pgadmin/misc/__init__.py b/web/pgadmin/misc/__init__.py index 7b395a53267..96c1fbb2ec5 100644 --- a/web/pgadmin/misc/__init__.py +++ b/web/pgadmin/misc/__init__.py @@ -326,16 +326,6 @@ def validate_binary_path(): return make_json_response(data=gettext(version_str), status=200) -def urlopen_with_ssl(url, data, timeout, cafile): - context = ssl.create_default_context(cafile=cafile) - if sys.version_info >= (3, 13): - # Use SSL context for Python 3.13+ - return urlopen(url, data=data, timeout=timeout, context=context) - else: - # Use cafile parameter for older versions - return urlopen(url, data=data, timeout=timeout, cafile=cafile) - - @blueprint.route("/upgrade_check", endpoint="upgrade_check", methods=['GET']) @pga_login_required