无法按原样对字符串进行编码或使用

2024-10-01 04:44:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从数据库中检索一些文本,在使用python3时,我看到了如下错误:

forgelogger\\n    print("%s | %s" % (time.strftime("%Y-%m-%d %H:%M:%S"), message))\\nUnicodeEncodeError: \\'ascii\\' codec can\\'t encode character \\'\\\\xad\\' in position 62: ordinal not in range(128)'

之后,我尝试按原样使用变量,并尝试.encode(),但随后我得到:

^{2}$

我也尝试过使用.decode(),但是:

AttributeError: \\'str\\' object has no attribute \\'decode\\''

我看不出哪个角色有问题。在

这曾经在python2上与unicode()一起工作,但现在不行了。 有什么建议吗?在

编辑: 如果有帮助,这是Trac的配置(我们正在查询的是它的数据库):

default_charset = iso-8859-15

Tags: in文本数据库messagetime错误asciipython3