Python中的MySQL:UnicodeEncodeError:'ascii' [英] MySQL in Python: UnicodeEncodeError: 'ascii'
本文介绍了Python中的MySQL:UnicodeEncodeError:'ascii'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试将字符串值存储到MySQL,并且我使用db.escape_string()以便避免转义特殊字符. 字符串是
Hello I am trying to store a string value to MySQL, and i use db.escape_string() so not to escape special characters. The string is
Lala*=#&%@<>_?!:;-'"/()¥¡¿
但是当我尝试运行代码时,出现此错误:
But when I try to run the code, I get this error:
UnicodeEncodeError:'ascii'编解码器无法对位置中的字符进行编码 23-25:序数不在范围内(128)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 23-25: ordinal not in range(128)
我该怎么办?
推荐答案
在运行脚本之前,我在bash中使用bash解决了我的Debian问题:
I solved the problem in my Debian using this in bash before running the script:
export PYTHONIOENCODING=utf-8
这篇关于Python中的MySQL:UnicodeEncodeError:'ascii'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文