'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

问题

rds_content = "{}, 执行了变更,sql语句:{}".format(ExecuteTime, sqls)

'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

解决方法:

由于字符串中包含中文字符,超出了acsii编码范围(128)。
只需要将字符串前面加上u字符,将其作为unicode进行处理即可。

rds_content = u"{}执行了变更,sql语句:{}".format(ExecuteTime, sqls)

参考

https://blog.csdn.net/lanyang123456/article/details/84436784

https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20

http://in355hz.iteye.com/blog/1860787

原文地址:https://www.cnblogs.com/lanyangsh/p/10011761.html