【问题标题】:Django ascii/utf-8 encoding error on Windows caused by ImageField [duplicate]由 ImageField 引起的 Windows 上的 Django ascii/utf-8 编码错误 [重复]
【发布时间】:2014-07-03 09:14:08
【问题描述】:

我在 Windows 上运行 Django 应用程序。

我注意到在我的一个模型中添加 ImageField 后它停止工作(当我评论此字段时,应用程序运行)。

我有以下错误:

UnicodeDecodeError:“ascii”编解码器无法解码位置 35 中的字节 0xb3:序数不在范围内 (128)

我试过设置局部变量:

export LANG='en_US.UTF-8' 
export LC_ALL='en_US.UTF-8'
export LC_LANG='en_US.UTF-8'

但这并没有帮助......

我尝试在manage.py中更改系统编码

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

但我有以下错误:

UnicodeDecodeError: 'utf8' codec can't decode byte 0xb3 in position 35: invalid start byte

我该如何解决?

【问题讨论】:

    标签: python django encoding


    【解决方案1】:

    是 Python 2.x 吗?将此行添加到文件的开头。

    # -*- coding: utf8 -*-
    

    或查看answer

    【讨论】:

      【解决方案2】:

      我能想到一些可能的解决方案。一,尝试用base64编码而不是直接编码。您也可以尝试使用 UTF-16 作为编解码器,看看是否有帮助。

      【讨论】:

        猜你喜欢
        • 2012-03-27
        • 1970-01-01
        • 2014-06-19
        • 2014-01-17
        • 1970-01-01
        • 1970-01-01
        • 2012-07-13
        • 1970-01-01
        • 2019-01-22
        相关资源
        最近更新 更多