diff --git a/lib/ansible/modules/packaging/language/maven_artifact.py b/lib/ansible/modules/packaging/language/maven_artifact.py index 25b4717929d..02afe130b13 100644 --- a/lib/ansible/modules/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/packaging/language/maven_artifact.py @@ -177,7 +177,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.urls import fetch_url -from ansible.module_utils._text import to_bytes +from ansible.module_utils._text import to_bytes, to_native, to_text def split_pre_existing_dir(dirname): @@ -428,7 +428,10 @@ class MavenDownloader: parsed_url = urlparse(remote_url) remote_md5 = self._local_md5(parsed_url.path) else: - remote_md5 = self._getContent(remote_url + '.md5', "Failed to retrieve MD5", False) + try: + remote_md5 = to_text(self._getContent(remote_url + '.md5', "Failed to retrieve MD5", False), errors='strict') + except UnicodeError as e: + return "Cannot retrieve a valid md5 from %s: %s" % (remote_url, to_native(e)) if(not remote_md5): return "Cannot find md5 from " + remote_url if local_md5 == remote_md5: @@ -441,7 +444,7 @@ class MavenDownloader: def _local_md5(self, file): md5 = hashlib.md5() with io.open(file, 'rb') as f: - for chunk in iter(lambda: f.read(8192), ''): + for chunk in iter(lambda: f.read(8192), b''): md5.update(chunk) return md5.hexdigest()