From fe94222873c4df5118e93cebe7e9d69439266ba0 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Wed, 6 Jan 2016 14:50:42 +1100 Subject: Do not decode HTTP reason phrase from Dogtag The HTTP reason phrase sent by Dogtag is assumed to be encoded in UTF-8, but the encoding used by Tomcat is dependent on system locale, causing decode errors in some locales. The reason phrase is optional and will not be sent in a future version of Tomcat[1], so do not bother decoding and returning it. [1] https://github.com/apache/tomcat/commit/707ab1c77f3bc189e1c3f29b641506db4c8bce37 Fixes: https://fedorahosted.org/freeipa/ticket/5578 Reviewed-By: Jan Cholasta --- ipapython/dogtag.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'ipapython') diff --git a/ipapython/dogtag.py b/ipapython/dogtag.py index 010e49652..1cb74719c 100644 --- a/ipapython/dogtag.py +++ b/ipapython/dogtag.py @@ -118,14 +118,14 @@ def ca_status(ca_host=None, use_proxy=True): ca_port = 443 else: ca_port = 8443 - status, reason, headers, body = unauthenticated_https_request( + status, headers, body = unauthenticated_https_request( ca_host, ca_port, '/ca/admin/ca/getStatus') if status == 503: # Service temporarily unavailable - return reason + return status elif status != 200: raise errors.RemoteRetrieveError( - reason=_("Retrieving CA status failed: %s") % reason) + reason=_("Retrieving CA status failed with status %d") % status) return _parse_ca_status(body) @@ -136,8 +136,8 @@ def https_request(host, port, url, secdir, password, nickname, :param url: The path (not complete URL!) to post to. :param body: The request body (encodes kw if None) :param kw: Keyword arguments to encode into POST body. - :return: (http_status, http_reason_phrase, http_headers, http_body) - as (integer, unicode, dict, str) + :return: (http_status, http_headers, http_body) + as (integer, dict, str) Perform a client authenticated HTTPS request """ @@ -165,8 +165,8 @@ def http_request(host, port, url, **kw): """ :param url: The path (not complete URL!) to post to. :param kw: Keyword arguments to encode into POST body. - :return: (http_status, http_reason_phrase, http_headers, http_body) - as (integer, unicode, dict, str) + :return: (http_status, http_headers, http_body) + as (integer, dict, str) Perform an HTTP request. """ @@ -179,8 +179,8 @@ def unauthenticated_https_request(host, port, url, **kw): """ :param url: The path (not complete URL!) to post to. :param kw: Keyword arguments to encode into POST body. - :return: (http_status, http_reason_phrase, http_headers, http_body) - as (integer, unicode, dict, str) + :return: (http_status, http_headers, http_body) + as (integer, dict, str) Perform an unauthenticated HTTPS request. """ @@ -219,15 +219,14 @@ def _httplib_request( res = conn.getresponse() http_status = res.status - http_reason_phrase = unicode(res.reason, 'utf-8') http_headers = res.msg.dict http_body = res.read() conn.close() except Exception as e: raise NetworkError(uri=uri, error=str(e)) - root_logger.debug('response status %d %s', http_status, http_reason_phrase) + root_logger.debug('response status %d', http_status) root_logger.debug('response headers %s', http_headers) root_logger.debug('response body %r', http_body) - return http_status, http_reason_phrase, http_headers, http_body + return http_status, http_headers, http_body -- cgit