diff --git a/Client/src/bkr/client/commands/cmd_update_inventory.py b/Client/src/bkr/client/commands/cmd_update_inventory.py index b1d8b7805..56f5e78c2 100644 --- a/Client/src/bkr/client/commands/cmd_update_inventory.py +++ b/Client/src/bkr/client/commands/cmd_update_inventory.py @@ -87,7 +87,6 @@ from __future__ import print_function -import cgi import sys from xml.dom.minidom import parseString @@ -95,6 +94,7 @@ from bkr.client import BeakerCommand from bkr.client.task_watcher import watch_tasks +from bkr.common.helpers import parse_content_type class Update_Inventory(BeakerCommand): @@ -152,7 +152,7 @@ def run(self, *args, **kwargs): res.raise_for_status() except HTTPError as e: sys.stderr.write('HTTP error: %s, %s\n' % (fqdn, e)) - content_type, _ = cgi.parse_header(e.response.headers.get( + content_type = parse_content_type(e.response.headers.get( 'Content-Type', '')) if content_type == 'text/plain': sys.stderr.write('\t' + diff --git a/Client/src/bkr/client/main.py b/Client/src/bkr/client/main.py index faca452d4..cd7f62ad2 100755 --- a/Client/src/bkr/client/main.py +++ b/Client/src/bkr/client/main.py @@ -5,7 +5,6 @@ # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -import cgi import errno import logging import signal @@ -22,6 +21,7 @@ from bkr.client.command import ClientCommandContainer from bkr.client.command import CommandOptionParser from bkr.common import __version__ +from bkr.common.helpers import parse_content_type from bkr.log import log_to_stream __all__ = ( @@ -129,7 +129,7 @@ def main(): except maybe_http_error as e: warn_on_version_mismatch(e.response) sys.stderr.write('HTTP error: %s\n' % e) - content_type, _ = cgi.parse_header(e.response.headers.get('Content-Type', '')) + content_type = parse_content_type(e.response.headers.get('Content-Type', '')) if content_type == 'text/plain': sys.stderr.write(e.response.content.decode('utf-8').rstrip('\n') + '\n') return 1 diff --git a/Common/bkr/common/helpers.py b/Common/bkr/common/helpers.py index f6c5c707a..7cbe36d95 100644 --- a/Common/bkr/common/helpers.py +++ b/Common/bkr/common/helpers.py @@ -278,3 +278,9 @@ def total_seconds(td): """ return (float(td.microseconds) + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 +def parse_content_type(value): + """ + Return just content type, without options + """ + groups = value.split(';', 1) + return groups[0]