【问题标题】:Django unable to save a text value in DBDjango 无法在 DB 中保存文本值
【发布时间】:2016-02-03 12:54:05
【问题描述】:

我正在我的 Django 应用程序中通过 IMAP 阅读电子邮件内容。

当我尝试将一些已解析的内容分配给对象并执行 .save() 时,它会返回:

ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

当我打印变量类型时: . DB 中的字段定义为 CharField。我也试过TextField,但结果是一样的。

我该如何解决?

【问题讨论】:

    标签: django python-2.7 django-models


    【解决方案1】:

    如果您的邮件文本在 mail_text 中,请执行以下操作:

    mail_text = unicode(mail_text)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 2021-05-21
      • 2012-10-02
      • 1970-01-01
      相关资源
      最近更新 更多