开发者社区> 问答> 正文

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')

展开
收起
a123456678 2016-06-15 15:54:21 5753 0
1 条回答
写回答
取消 提交回答
  • screenshot

    2019-07-17 19:39:31
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
2.pdf[游客qs2gfrl2557dq].1554006234.pdf 立即下载
Constrained Output Embeddings for End-to-End Code-Switching Speech Recognition with Only Monolingual Data 立即下载
低代码开发师(初级)实战教程 立即下载