【python 编码问题】UnicodeEncodeError: 'ascii' codec can't encode characters in position 176-178: ordinal

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 176-178: ordinal not in range(128)
错误解决:
问题描述:在centos 下 执行 sql 语句,where条件里面含有中文,说是数据库编码和系统编码不一致导致。

Traceback (most recent call last):
  File "sensitive_word_api.py", line 129, in <module>
    dfa_chi, dfa_eng, dfa, data = load_sensitive_words_task0()
  File "sensitive_word_api.py", line 46, in load_sensitive_words_task0
    cursor.execute(query)
  File "/opt/anaconda3/lib/python3.6/site-packages/DBUtils/SteadyDB.py", line 605, in tough_method
    result = method(*args, **kwargs)  # try to execute
UnicodeEncodeError: 'ascii' codec can't encode characters in position 176-178: ordinal not in range(128)

编码虐我千百遍,最终还是找到了解决办法
解决办法:进入 root 用户 ,编辑 /etc/profile/文件,加入下面两句

vim /etc/profile

export LC_ALL="en_US.utf8"
export NLS_LANG='Simplified Chinese_CHINA.ZHS16GBK'



source /etc/profile

即可完美解决。

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页