diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index 7a8c1a24ab..4a8c58eb29 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -301,7 +301,15 @@ class NovaClientPlugin(client_plugin.ClientPlugin): subtype = os.path.splitext(filename)[0] if content is None: content = '' - msg = text.MIMEText(content, _subtype=subtype) + + try: + content.encode('us-ascii') + charset = 'us-ascii' + except UnicodeEncodeError: + charset = 'utf-8' + msg = (text.MIMEText(content, _subtype=subtype, _charset=charset) + if subtype else text.MIMEText(content, _charset=charset)) + msg.add_header('Content-Disposition', 'attachment', filename=filename) return msg diff --git a/heat/engine/resources/openstack/heat/multi_part.py b/heat/engine/resources/openstack/heat/multi_part.py index 09c8bf0f16..0bd8c9a16e 100644 --- a/heat/engine/resources/openstack/heat/multi_part.py +++ b/heat/engine/resources/openstack/heat/multi_part.py @@ -154,8 +154,15 @@ class MultipartMime(software_config.SoftwareConfig): @staticmethod def _create_message(part, subtype, filename): - msg = (text.MIMEText(part, _subtype=subtype) - if subtype else text.MIMEText(part)) + charset = 'us-ascii' + try: + part.encode(charset) + except UnicodeEncodeError: + charset = 'utf-8' + msg = (text.MIMEText(part, _subtype=subtype, + _charset=charset) + if subtype else text.MIMEText(part, _charset=charset)) + if filename: msg.add_header('Content-Disposition', 'attachment', filename=filename)