UnicodeEncodeError:“ascii"编解码器无法编码字符 [英] UnicodeEncodeError: 'ascii' codec can't encode character

查看:38
本文介绍了UnicodeEncodeError:“ascii"编解码器无法编码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传包含非 ASCII 字符的文件时,出现 UnicodeEncodeError:

When uploading files with non-ASCII characters I get UnicodeEncodeError:

Exception Type: UnicodeEncodeError at /admin/studio/newsitem/add/
Exception Value: 'ascii' codec can't encode character u'xf8' in position 78: ordinal not in range(128)

请参阅完整堆栈跟踪.

我使用 MySQL、nginx 和 FastCGI 运行 Django 1.2.

I run Django 1.2 with MySQL and nginx and FastCGI.

这是根据 Django Trac 数据库解决的问题,但我仍然有问题.欢迎任何有关如何修复的建议.

This is a problem that is fixed according to the Django Trac database, but I still have the problem. Any suggestions on how to fix are welcome.

这是我的图像字段:

image = models.ImageField(_('image'), upload_to='uploads/images', max_length=100)

推荐答案

在调查了一些之后,我发现我没有在我的主 Nginx 配置文件中设置字符集:

After investigating this some more I found out that I hadn't set the charset in my main Nginx config file:

http {
  charset  utf-8;
}

通过添加上面的,问题就消失了,我认为这是处理这个问题的正确方法.

By adding the above, the problem disappeared and I think that this is the correct way of handling this issue.

这篇关于UnicodeEncodeError:“ascii"编解码器无法编码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆