

python3 mysqlclient1.4.2在centos7 执行 `select * from table where a = '中文';`...
source link: https://qidizi.github.io/python3-mysqlclient-centos%E8%A7%A6%E5%8F%91latin-1%E5%BC%82%E5%B8%B8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

python3 mysqlclient1.4.2在centos7 执行 `select * from table where a = '中文';` 出现了`UnicodeEncodeError: 'latin-1' codec can't encode characters`异常
在连接时设置一下 charset='utf8'
即可解决
_me._mysql = _mysql = Mysql.connect(
host=ConfigCustom.get_mysql_host(),
password=ConfigCustom.get_mysql_pwd(),
port=ConfigCustom.get_mysql_port(),
user=ConfigCustom.get_mysql_user(),
db=ConfigCustom.get_mysql_db(),
use_unicode=True,
# 否则有些系统会触发
# UnicodeEncodeError: 'latin-1' codec can't encode characters in position 34-35:
# ordinal not in range(256)
charset='utf8',
connect_timeout=30, # 这个参数好像无效,还是默认使用60来
autocommit=True, # 它默认是否
)
_me._cursor = _me._mysql.cursor()
前篇:关于centos 7自动同步时间的正确打开方式
后篇:centos 7开机提示selinux规则加载失败解决方案
Recommend
-
47
过去2年开始微软一直在沸沸扬扬地宣传PowerShellcore,可以允许Windows的管理员在Linux/OSX平台执行Powershell的管理命令。很多第三方的厂商也纷纷推出了自己的管理模块。不过对比起Windows下面的Powershell,Powershellcore现在支持的模块实在太少,存在的bug也很...
-
46
第一步、查看python的版本号以及安装路径; 通过以上的查看可以看到,python默认是指向到python2的,所以这里我们不动它,保持现状态...
-
8
在Centos7系统中,默认带的Python版本是Python2.7的,想用到Python3的新特性就需要升级.安装依赖包关于Python3.7以上的版本,需要多安装一个依赖包:> yum install -y libffi-deve...
-
10
宝塔面板Centos7环境下如何使Python2与Python3共存 2021-11-2314:09:12
-
4
准备安装Python3、下载Python3 一、安装依赖包,这个具体的作用我也不清楚,感觉好像是在安装的时候会要用到的工具。 y...
-
4
具体编译过成与正常的Python源代码在x86平台上的过程无异,此篇随笔仅当用作复制黏贴的备忘录。不得不说在一个老旧系统上安装一个老旧的Python版本,从头编译一个Python还是一个较为稳健的选择。 获取源代码 Python官网处下载所需源...
-
6
V2EX › Linux CentOS7 需要在开机时执行一个一次性脚本,请问如何操作?
-
5
处理Centos6和Centos7下,python3处理中文的神坑首页 - Python/2019-04-10 在一个阿里云的ecs服务器上,安装...
-
2
【笔记】Python3获取中文拼音首字母 2023-04-25 ...
-
4
环境:CentOS 7.6_x64 Python版本 :3.9.12 pjsip版本:2.13 一、背景描述 pjsip地址:https://www.pjsip.org/ GitHub地址:
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK