Hi,<br><br>Recently I encountered a problem with the str.encode() function.&nbsp; I used the function like this: s.encode(&quot;mbcs&quot;, &quot;replace&quot;), expecting it will eliminate all invalid characters.&nbsp; However it failed with the following message: UnicodeEncodeError: &#39;gbk&#39; codec can&#39;t encode character &#39;\ue104&#39; in position 4: i<br>
<br>Am I using it in a wrong way or is it a bug?<br><br>Platform: Windows Vista SP1, system default code page: 936 (zh-cn).&nbsp; Program (test.py.txt) in attachment.<br><br>&gt;python3 test.py<br>A<br>Traceback (most recent call last):<br>
&nbsp; File &quot;test.py&quot;, line 7, in &lt;module&gt;<br>&nbsp;&nbsp;&nbsp; print(str.encode(&quot;mbcs&quot;, &quot;replace&quot;).decode(&quot;mbcs&quot;, &quot;replace&quot;))<br>&nbsp; File &quot;C:\Python30\lib\io.py&quot;, line 1485, in write<br>
&nbsp;&nbsp;&nbsp; b = encoder.encode(s)<br>UnicodeEncodeError: &#39;gbk&#39; codec can&#39;t encode character &#39;\ue104&#39; in position 4: i<br>llegal multibyte sequence<br>&gt;python3 test.py<br>A<br>??íé“øô{??‰ã°„˜z<br>B<br>&gt;python3 test.py<br>
A<br>’é??????ñqÀÕèŸ<br>B<br><br>Thanks,<br><br>Decheng (AKA Robbie Mosaic) Fan<br>