Skip to content

Commit 06e5960

Browse files
committed
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
1 parent badc6f3 commit 06e5960

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

web/pgadmin/misc/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import time
3030
import json
3131
import os
32+
import sys
33+
import ssl
3234
from urllib.request import urlopen
3335
from pgadmin.settings import get_setting, store_setting
3436

@@ -324,6 +326,16 @@ def validate_binary_path():
324326
return make_json_response(data=gettext(version_str), status=200)
325327

326328

329+
def urlopen_with_ssl(url, data, timeout, cafile):
330+
context = ssl.create_default_context(cafile=cafile)
331+
if sys.version_info >= (3, 13):
332+
# Use SSL context for Python 3.13+
333+
return urlopen(url, data=data, timeout=timeout, context=context)
334+
else:
335+
# Use cafile parameter for older versions
336+
return urlopen(url, data=data, timeout=timeout, cafile=cafile)
337+
338+
327339
@blueprint.route("/upgrade_check", endpoint="upgrade_check",
328340
methods=['GET'])
329341
@pga_login_required
@@ -346,7 +358,8 @@ def upgrade_check():
346358
# It stuck on rendering the browser.html, while working in the
347359
# broken network.
348360
if os.path.exists(config.CA_FILE):
349-
response = urlopen(url, data, 5, cafile=config.CA_FILE)
361+
response = urlopen_with_ssl(
362+
url, data, 5, config.CA_FILE)
350363
else:
351364
response = urlopen(url, data, 5)
352365
current_app.logger.debug(

0 commit comments

Comments
 (0)