编解码器不能编码字符

编解码器不能编码字符

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

问题描述

当使用非ASCII字符上传文件时,我得到UnicodeEncodeError:

 异常类型:在/ admin / studio / newsitem中的UnicodeEncodeError / add / 
异常值:'ascii'编解码器不能在位置78编码字符u'\xf8':序号不在范围(128)

请参阅。 p>

我运行Django 1.2与MySQL和nginx和FastCGI。



这是一个根据,但我仍然有问题。欢迎任何有关如何修复的建议。



编辑:这是我的图像字段:

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


解决方案

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

  http {
charset utf-8;
}

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


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)

See full stack trace.

I run Django 1.2 with MySQL and nginx and FastCGI.

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.

EDIT: This is my image field:

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

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'编解码器不能编码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:48