From 98ec299fa62d8ba1e920df2243ca7117d366cc74 Mon Sep 17 00:00:00 2001 From: Yufei Date: Fri, 13 Jan 2017 01:24:38 +0800 Subject: [PATCH] Avoid TypeError after _replace when user post a str url function geturl will rasie a TypeError if we specify a str url and replace the scheme value with a unicode value. In order to work with both string redfish url and unicode redfish url, we need to convert the "https" to the scheme's type. This bug canbe reproduced with: from __future__ import unicode_literals from __future__ import print_function from __future__ import division from __future__ import absolute_import from future import standard_library standard_library.install_aliases() from builtins import object import json from urllib.parse import urlparse, urljoin, urlunparse url=urlparse(unicode("http://127.0.0.1")) url._replace(scheme="https").geturl() url=urlparse(str("http://127.0.0.1")) url._replace(scheme="https").geturl() Change-Id: I1aa0f173a7b843c2bdf3eba8425ff794778b74da --- redfish/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redfish/main.py b/redfish/main.py index 9b8267d..33fc02c 100644 --- a/redfish/main.py +++ b/redfish/main.py @@ -196,7 +196,7 @@ class RedfishConnection(object): # Enforce ssl if self.connection_parameters.enforceSSL is True: config.logger.debug("Enforcing SSL") - rooturl = rooturl._replace(scheme="https") + rooturl = rooturl._replace(scheme=type(rooturl.scheme)("https")) self.connection_parameters.rooturl = rooturl.geturl() # Verify cert