diff --git a/Lib/email/_policybase.py b/Lib/email/_policybase.py index 12211158f4699b..9558691402d458 100644 --- a/Lib/email/_policybase.py +++ b/Lib/email/_policybase.py @@ -97,7 +97,7 @@ def validate_header(name): raise ValueError(f"Invalid header field name {name!r}") # Only allow printable ASCII characters if any(ord(c) < 33 or ord(c) > 126 for c in name): - raise ValueError(f"Header field name {name!r} contains invalid characters") + raise ValueError(f"Invalid header field name {name!r}") def _append_doc(doc, added_doc): doc = doc.rsplit('\n', 1)[0] diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 827b36c36bd3a6..ade9d3a2ac28f5 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -740,7 +740,7 @@ def test_invalid_headers(self): for name, value in invalid_headers: with self.assertRaises(ValueError) as cm: Message().add_header(name, value) - self.assertIn("Invalid header field name", str(cm.exception)) + self.assertIn(f"Invalid header field name {name!r}", str(cm.exception)) invalid_headers = [ ('Header\x7F', 'Non-ASCII character'), @@ -749,7 +749,7 @@ def test_invalid_headers(self): for name, value in invalid_headers: with self.assertRaises(ValueError) as cm: Message().add_header(name, value) - self.assertIn(f"Header field name {name!r} contains invalid characters", str(cm.exception)) + self.assertIn(f"Invalid header field name {name!r}", str(cm.exception)) def test_binary_quopri_payload(self): for charset in ('latin-1', 'ascii'):