背景及环境
- 说明:
- 将salt-minion的结果同时保存到mysql数据库中,方便进行平台的开发
- 同时验证了mysqlclient和PyMySQL,验证时都可以
- 版本情况
组件 版本 linux centos 7.5 python 3.6 saltstack 3000.6 mysqlclient 2.0.3
问题描述
saltstack mysql returns报错:
2021-06-08 18:35:54,589 [salt.minion :1820][ERROR ][67733] The return failed for job 20210608103516743716: 'charmap' codec can't encode characters in position 37750-37751: character maps to <undefined>
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/minion.py", line 1811, in _thread_return
minion_instance.returners[returner_str](ret)
File "/usr/lib/python3.6/site-packages/salt/returners/mysql.py", line 308, in returner
salt.utils.json.dumps(ret)))
File "/usr/local/lib64/python3.6/site-packages/MySQLdb/cursors.py", line 199, in execute
args = tuple(map(db.literal, args))
File "/usr/local/lib64/python3.6/site-packages/MySQLdb/connections.py", line 280, in literal
s = self.string_literal(o.encode(self.encoding))
File "/usr/lib64/python3.6/encodings/cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 37750-37751: character maps to <undefined>
解决步骤
- 第一阶段
怀疑是自己写的sls文件有问题
- 将怀疑的sls文件重写,严格安装yaml标准格式进行编写,问题依旧
- 将所有的sls单独执行,没有报错
- 同时前后端一起联调,解决其他发现的问题
- 第二阶段
将前端和业务逻辑层面的问题解决,问题依然存在
- 再次细看报错信息,最后的问题点其实是跟mysql相关的库强相关
- 尝试卸载mysqlclient,使用PyMySQL代替——问题解决