6
回答
django 上传一个带有中文名的照片的时候,出现了以下错误:“'ascii' codec can't encode characters in position 50-52: ordinal not in range(128)”

django 上传一个带有中文名的照片的时候,出现了以下错误:“'ascii' codec can't encode characters in position 50-52: ordinal not in range(128)”

 

Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File "/var/www/html/www.gq2018.com/gqinfo/views.py" in info_post
  65.             newinfo.save()
File "/usr/lib/python2.6/site-packages/django/db/models/base.py" in save
  546.                        force_update=force_update, update_fields=update_fields)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py" in save_base
  650.                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py" in _insert
  215.         return insert_query(self.model, objs, fields, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in insert_query
  1675.     return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  936.         for sql, params in self.as_sql():
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in as_sql
  894.                 for obj in self.query.objs
File "/usr/lib/python2.6/site-packages/django/db/models/fields/files.py" in pre_save
  250.             file.save(file.name, file, save=False)
File "/usr/lib/python2.6/site-packages/django/db/models/fields/files.py" in save
  86.         self.name = self.storage.save(name, content)
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py" in save
  47.         name = self.get_available_name(name)
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py" in get_available_name
  73.         while self.exists(name):
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py" in exists
  243.         return os.path.exists(self.path(name))
File "/usr/lib/python2.6/genericpath.py" in exists
  18.         st = os.stat(path)

Exception Type: UnicodeEncodeError at /post/
Exception Value: 'ascii' codec can't encode characters in position 55-56: ordinal not in range(128)

 

 

我试了:

 

#encoding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

 

还按这上面试了:http://www.07net01.com/linux/Djangochuxiande_ascii__codec_can_t_encode_characters_in_positio_11063_1345791548.html

 

上面说是在

在/etc/apache2/envvars文件加上:

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

我是用的centos 没找到envvars 不知道在哪里加?

我直接在/etc/httpd 里建了一个envvars 然后加上上面的代码。然后重启服务器还是不管用。

我是用的django1.52+python2.6  +mod_wsgi apache centos  这个还有别的什么办法处理不?

 

举报
gq2018
发帖于5年前 6回/1K+阅
顶部