Files
doc-exports/docs/dataartsstudio/umn/dataartsstudio_03_0417.html
chenxiaoxiong f9e2808b7c DataArts UMN 20250810 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: chenxiaoxiong <chenxiaoxiong@huawei.com>
Co-committed-by: chenxiaoxiong <chenxiaoxiong@huawei.com>
2025-09-02 10:44:13 +00:00

29 lines
3.2 KiB
HTML

<a name="dataartsstudio_03_0417"></a><a name="dataartsstudio_03_0417"></a>
<h1 class="topictitle1">What Should I Do If Error Message "UnicodeEncodeError: 'ascii' codec can't encode characters in position 63-64: ordinal not in range(128)" Is Displayed When I Run a Python Script?</h1>
<div id="body0000001450175573"><p id="dataartsstudio_03_0417__p1096055818194">This error occurs when <strong id="dataartsstudio_03_0417__b042382242710">json.dumps(json_data, ensure_ascii=False)</strong> is configured in the Python script. The following figure shows the error.</p>
<div class="fignone" id="dataartsstudio_03_0417__fig35001642165720"><span class="figcap"><b>Figure 1 </b>Error message</span><br><span><img id="dataartsstudio_03_0417__image784428173114" src="en-us_image_0000002234076304.png" title="Click to enlarge" class="imgResize"></span></div>
<div class="section" id="dataartsstudio_03_0417__section9706356113111"><h4 class="sectiontitle">Possible Cause</h4><p id="dataartsstudio_03_0417__p15670131123212">By default, DataArts Studio uses the Python2 interpreter. This interpreter uses the ASCII encoding format by default and cannot encode Chinese characters. As a result, the error occurs. Therefore, you need to convert the encoding format to UTF-8.</p>
</div>
<div class="section" id="dataartsstudio_03_0417__section14228320184018"><h4 class="sectiontitle">Solution</h4><ol id="dataartsstudio_03_0417__ol11145183310423"><li id="dataartsstudio_03_0417__li7145633104214">Use the Python3 interpreter to create a soft connection on the host.<div class="fignone" id="dataartsstudio_03_0417__fig6945140189"><span class="figcap"><b>Figure 2 </b>Creating a soft connection on the host</span><br><span><img id="dataartsstudio_03_0417__image14303711131111" src="en-us_image_0000002234236144.png" title="Click to enlarge" class="imgResize"></span></div>
</li><li id="dataartsstudio_03_0417__li1844024254211">Set the standard encoding mode in the file.<p id="dataartsstudio_03_0417__p177841337165714"><a name="dataartsstudio_03_0417__li1844024254211"></a><a name="li1844024254211"></a># -*- coding: utf-8 -*-; Alternatively, set the encoding format for the host, that is, create a <strong id="dataartsstudio_03_0417__b1239344055118">sitecustomize.py</strong> file in the <strong id="dataartsstudio_03_0417__b16393174010519">Lib\site-packages</strong> folder in the Python installation directory and write the following information in the file:</p>
<pre class="screen" id="dataartsstudio_03_0417__screen580359412">#<em id="dataartsstudio_03_0417__i106362471449"> encoding=utf8</em>
#import sys
#reload(sys)
#sys.setdefaultencoding('utf8')</pre>
</li><li id="dataartsstudio_03_0417__li0858526124313">Restart Python and run <strong id="dataartsstudio_03_0417__b2627135419512">sys.getdefaultencoding()</strong> to view the default encoding format, which is <strong id="dataartsstudio_03_0417__b1762717548519">utf8</strong>.</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dataartsstudio_03_0035.html">DataArts Factory</a></div>
</div>
</div>
<script language="JavaScript">
<!--
initImageViewer('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>