ninia / jep

Embed Python in Java
Other
1.28k stars 145 forks source link

output string with error #484

Closed scape7yu closed 11 months ago

scape7yu commented 11 months ago

When I output English, everything is ok, but when I output Chinese, error comes.

For example:


# output with print
print('中文')
# UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

# or

# output a excel file of Chinese name
import xlwt

workbook = xlwt.Workbook(encoding='utf-8')
# some code ...
workbook.save('/tmp/中文.xls')
# UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-6: ordinal not in range(128)
bsteffensmeier commented 11 months ago

That print statement works correctly on my system without any errors. I suspect there is a problem with your locale settings. I recommend reading more about how Python handles different locale settings. My system seems to be using a UTF-8 encoding while it appears your system is using ascii so I would recommend trying to change settings to get a UTF-8 encoding.

scape7yu commented 11 months ago

Thanks for your advice, my code is running on Docker, after I set up it's LANG=zh_CN.UTF-8, this problem disappeared. So, it's not a issue about JEP.