2012-05-03 109 views
1

在Django應用程序中,用戶正在使用表單上傳圖像。我不知道爲什麼。我能夠上傳帶有重音字符的文件。唯一的例外是下面上傳圖像時出現異常UnicodeEncodeError

File "pathto/python2.7/django/core/handlers/base.py", line 111, in get_response 
 
    response = callback(request, *callback_args, **callback_kwargs) 

File "/pathto/python2.7/django/contrib/auth/decorators.py", line 23, in _wrapped_view 
    return view_func(request, *args, **kwargs) 

File "/pathto/views.py", line 75, in upload_image 
    obj = form.save(request.user) 

File "/form.py", line 88, in save 
    obj.save() 

File "/pahtto/python2.7/django/db/models/base.py", line 460, in save 
    self.save_base(using=using, force_insert=force_insert, force_update=force_update) 

File "/pathto/python2.7/django/db/models/base.py", line 543, in save_base 
    for f in meta.local_fields if not isinstance(f, AutoField)] 

File "/pathto/lib/python2.7/django/db/models/fields/files.py", line 255, in pre_save 
    file.save(file.name, file, save=False) 

File "/pathto/extrantool.py", line 96, in save 
    super(ImageWithThumbsFieldFile, self).save(name, content, save) 

File "/pathto/python2.7/django/db/models/fields/files.py", line 92, in save 
    self.name = self.storage.save(name, content) 

File "/pathto/python2.7/django/core/files/storage.py", line 48, in save 
    name = self.get_available_name(name) 

File "/pathto/python2.7/django/core/files/storage.py", line 74, in get_available_name 
    while self.exists(name): 

File "/pathto/python2.7/django/core/files/storage.py", line 218, in exists 
    return os.path.exists(self.path(name)) 

File "/usr/local/lib/python2.7/genericpath.py", line 18, in exists 
    os.stat(path) 

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 66: ordinal not in range(128)
+0

該消息不是來自PostgreSQL,所以看看你的堆棧的其他部分。 – kgrittn

+0

我們需要查看您的模型和發佈的值,以便找出問題所在。聽起來就像文件名中有一個非ascii字符。 – Brandon

+0

你有自定義'upload_to'處理程序嗎?它一直與unicode一起工作嗎? – ilvar

回答

2

在猜測,布蘭登是正確的,是有文件名中的非ASCII字符。谷歌搜索您的錯誤信息

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 66 

給了我下面的前兩個環節:

  1. Python Unicode Error blog entry
  2. Python official Unicode docs

添加 「的Django」 的搜索實際上給了我們的StackOverflow回答!

UnicodeEncodeError: 'ascii' codec can't encode character

所以 - 檢查你的語言設置爲Django的將是我的建議。

相關問題