Title: Issues with Shift_JIS and EUC-JP in email · Issue #150771 · python/cpython · GitHub
Open Graph Title: Issues with Shift_JIS and EUC-JP in email · Issue #150771 · python/cpython
X Title: Issues with Shift_JIS and EUC-JP in email · Issue #150771 · python/cpython
Description: Bug report The following example: from email.message import EmailMessage from email.contentmanager import raw_data_manager m = EmailMessage() content = "\u65e5\u672c\u8a9e\n" raw_data_manager.set_content(m, content, charset='shift_jis') ...
Open Graph Description: Bug report The following example: from email.message import EmailMessage from email.contentmanager import raw_data_manager m = EmailMessage() content = "\u65e5\u672c\u8a9e\n" raw_data_manager.set_c...
X Description: Bug report The following example: from email.message import EmailMessage from email.contentmanager import raw_data_manager m = EmailMessage() content = "\u65e5\u672c\u8a9e\n" raw_data_man...
Opengraph URL: https://github.com/python/cpython/issues/150771
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Issues with Shift_JIS and EUC-JP in email","articleBody":"# Bug report\n\nThe following example:\n\n```py\nfrom email.message import EmailMessage\nfrom email.contentmanager import raw_data_manager\n\nm = EmailMessage()\ncontent = \"\\u65e5\\u672c\\u8a9e\\n\"\nraw_data_manager.set_content(m, content, charset='shift_jis')\nprint(m)\n```\n\nfails with exception\n\n```pytb\nTraceback (most recent call last):\n File \"\u003cpython-input-0\u003e\", line 7, in \u003cmodule\u003e\n print(m)\n ~~~~~^^^\n File \"/home/serhiy/py/cpython/Lib/email/message.py\", line 1015, in __str__\n return self.as_string(policy=self.policy.clone(utf8=True))\n ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/message.py\", line 1012, in as_string\n return super().as_string(unixfrom, maxheaderlen, policy)\n ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/message.py\", line 194, in as_string\n g.flatten(self, unixfrom=unixfrom)\n ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/generator.py\", line 118, in flatten\n self._write(msg)\n ~~~~~~~~~~~^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/generator.py\", line 183, in _write\n self._dispatch(msg)\n ~~~~~~~~~~~~~~^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/generator.py\", line 220, in _dispatch\n meth(msg)\n ~~~~^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/generator.py\", line 258, in _handle_text\n msg.set_payload(msg._payload, charset)\n ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/message.py\", line 361, in set_payload\n self.set_charset(charset)\n ~~~~~~~~~~~~~~~~^^^^^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/message.py\", line 392, in set_charset\n self._payload = charset.body_encode(self._payload)\n ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^\n File \"/home/serhiy/py/cpython/Lib/email/charset.py\", line 441, in body_encode\n string = string.encode(self.output_charset).decode('ascii')\n ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\nUnicodeEncodeError: 'iso2022_jp' codec can't encode character '\\udc93' in position 0: illegal multibyte sequence\nencoding with 'iso-2022-jp' codec failed\n```\n\nThe same for euc-jp. \"shift_jis\" and \"euc-jp\" are two charsets in `email.charset.CHARSETS` for which the output charset is overridden.\n\nThis fails in Python from 3.11 to main. It worked in Python 3.10 and older.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-151120\n* gh-151541\n* gh-152952\n* gh-152953\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-06-02T09:10:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/150771/cpython/issues/150771"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:451fc39d-362d-24e5-4d8f-54d090916e52 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9DB6:11EE4:1080614:16EB131:6A4E92D7 |
| html-safe-nonce | f297d40dbe63fc771d367a8ed3d4b474a015f864f434d847e399954c3b437ee0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5REI2OjExRUU0OjEwODA2MTQ6MTZFQjEzMTo2QTRFOTJENyIsInZpc2l0b3JfaWQiOiI4NzY4NTc4NDQ1NTg2MTA5MTQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | befde3afd20cb29bbbfca7692978ed311fad49e5fec9026c13efaba64366149a |
| hovercard-subject-tag | issue:4570075600 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/150771/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cd5e5c6b85e6ab6a1a5c515defd00af5333e438182c3e138202ad1e7edda2367/python/cpython/issues/150771 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cd5e5c6b85e6ab6a1a5c515defd00af5333e438182c3e138202ad1e7edda2367/python/cpython/issues/150771 |
| og:image:alt | Bug report The following example: from email.message import EmailMessage from email.contentmanager import raw_data_manager m = EmailMessage() content = "\u65e5\u672c\u8a9e\n" raw_data_manager.set_c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width