开发者社区> 问答> 正文

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

a123456678 2016-06-15 15:54:21 1679
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')
SQL 编解码 Python
分享到
取消 提交回答
全部回答(1)
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题