<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[UnicodeEncodeError: &#x27;gbk&#x27; codec can&#x27;t encode character &#x27;&#x5C;u2649&#x27; in position 4: illegal multibyte sequence]]></title><description><![CDATA[<p dir="auto">As shown in the figure, when running Python code, notepad++ reports an error “UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\u2649’ in position 4: illegal multibyte sequence”.</p>
<p dir="auto">The same code will not report an error when running on vscode. What is the reason? How should notepad++ be set? Thank you for your answers.</p>
<p dir="auto"><img src="/assets/uploads/files/1723908570802-%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE-2024-08-17-190206.png" alt="屏幕截图 2024-08-17 190206.png" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1723908574669-%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE-2024-08-17-190143.png" alt="屏幕截图 2024-08-17 190143.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/topic/26023/unicodeencodeerror-gbk-codec-can-t-encode-character-u2649-in-position-4-illegal-multibyte-sequence</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 08:58:34 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/26023.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Aug 2024 15:34:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to UnicodeEncodeError: &#x27;gbk&#x27; codec can&#x27;t encode character &#x27;&#x5C;u2649&#x27; in position 4: illegal multibyte sequence on Sun, 18 Aug 2024 11:34:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/31362">@mabangde0</a></p>
<p dir="auto">see <a href="https://sourceforge.net/p/npp-plugins/discussion/672146/thread/d94ff609/" rel="nofollow ugc">here</a> for a solution to your problem</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96198</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96198</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Sun, 18 Aug 2024 11:34:04 GMT</pubDate></item><item><title><![CDATA[Reply to UnicodeEncodeError: &#x27;gbk&#x27; codec can&#x27;t encode character &#x27;&#x5C;u2649&#x27; in position 4: illegal multibyte sequence on Sun, 18 Aug 2024 10:47:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a> Thank you for your answer, here is the original code:</p>
<p dir="auto">n = eval(input(“请输入一个数字:”))<br />
print(“{:+^11}”.format(chr(n-1)+chr(n)+chr(n+1)))</p>
<p dir="auto">After running, enter 9802 in the console to reproduce.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96196</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96196</guid><dc:creator><![CDATA[mabangde0]]></dc:creator><pubDate>Sun, 18 Aug 2024 10:47:00 GMT</pubDate></item><item><title><![CDATA[Reply to UnicodeEncodeError: &#x27;gbk&#x27; codec can&#x27;t encode character &#x27;&#x5C;u2649&#x27; in position 4: illegal multibyte sequence on Sat, 17 Aug 2024 16:58:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/31362">@mabangde0</a> ,</p>
<p dir="auto">it’s python.exe, not Notepad++, which is giving you that error.  However, since Notepad++'s use of encoding might be the culprit, it’s still on-topic here.</p>
<p dir="auto">Possibly, the file is not saved with the encoding that you think it is in Notepad++.  You will want to look at Notepad++'s Encoding menu’s selection, and/or the status bar (which you didn’t show in the screenshot):</p>
<p dir="auto"><img src="/assets/uploads/files/1723911089850-007b5bac-2f23-48f0-a3ed-6d0142ff078c-image.png" alt="007b5bac-2f23-48f0-a3ed-6d0142ff078c-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Also, look to see what encoding VSCode claims it is.</p>
<p dir="auto">If I remember correctly, without an <code># encoding=...</code> or similar, python3 assumes UTF-8.  I know that the one I showed has an error when I do UTF-8 – but I just used OCR on your screenshot to try to get <em>similar</em> characters… I have no idea how to enter the exact characters.  (it would have been nice if you’d clicked on <code>&lt;/&gt;</code> in the forum, then put your example code, with the right characters, in between the <code>```</code> lines, so we could copy/paste.)  So it might be that by pasting from OCR, I got characters that won’t encode correctly.</p>
<p dir="auto"><s>When looking at the error I get when I do Notepad++ in UTF-8, I thought Notepad++ might be using the surrogate pairs (<code>U+D800</code>–<code>U+DFFF</code>) to encode the <code>U+1xxxx</code>, and then encodes <em>those</em> into UTF-8 in the file.  I don’t think UTF-8 normally needs/uses surrogate pairs, so that might be confusing the Python interpreter.  (I think “modified UTF-8” allows it, but maybe not normal UTF-8.)  And since <a href="https://docs.python.org/3.12/library/codecs.html#standard-encodings" rel="nofollow ugc">Python 3.12 codecs</a> says that it doesn’t support surrogates for even UTF-16 (which are the encodings for which surrogate pairs are defined), it wouldn’t surprise me if Python doesn’t accept the surrogates for UTF-8 either.  But someone who knows more about Python’s encoding rules would really need to chime in for that.</s> <em>But before posting, while re-reading, I noticed that it wasn’t actually listing anything in the surrogate-pair range, so this paragraph was probably wrong – at least for the characters I used; maybe your characters do, I’m not sure.</em></p>
<p dir="auto">Since your error message included “gbk”, I tried setting <code># encoding=gbk</code> (which was listed in Python’s codecs), but then couldn’t find a Notepad++ Encoding (at least not in the <strong>Encoding &gt; Character Set &gt; Chinese</strong>) that matched GBK .  I tried <code># encoding=gb2312</code> and using that encoding in Notepad++ gives me <code>SyntaxError: encoding problem: gb2312</code> instead…</p>
<p dir="auto">(But I’m not an expert on Chinese encodings – everything that seems right in anything I said above specifically about those encodings was only because google apparently gave me good answers; anything that’s wrong is probably my fault for not understanding/interpreting correctly.)</p>
<p dir="auto">I guess I might just be wasting everyone’s time, other than suggesting that you double-check encodings on both applications to see if there’s a difference.  Sorry for the rambling.  Maybe there’s someone else who has more experience with Chinese characters and python and Notepad++ all working together, who can come give you a real answer.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96185</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96185</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sat, 17 Aug 2024 16:58:55 GMT</pubDate></item></channel></rss>