- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在生产服务器上遇到 unicode 文件名问题。当我尝试保存文件时,发生 UnicodeEncodeError 异常。 Devserver 工作正常。
www-data 的所有语言环境都是“en_US.UTF-8”。
另外,我在/etc/apache2/envvars中写下了
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
它没有帮助。
locale.getdefaultlocale() 返回 (None,None),然后我将以下行添加到 django.wsgi
os.environ['LANG']='en_US.UTF-8'
os.environ['LC_ALL']='en_US.UTF-8'
在 locale.getdefaultlocale() 开始返回 ('en_US', 'UTF8') 之后
我注意到 sys.getdefaultencoding() 返回“ascii”,但我不知道如何修复它。
回溯:
Traceback:
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/contrib/admin/options.py" in wrapper
366. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/contrib/admin/sites.py" in inner
196. return view(request, *args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/utils/decorators.py" in _wrapper
25. return bound_func(*args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/utils/decorators.py" in bound_func
21. return func(self, *args2, **kwargs2)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/transaction.py" in inner
209. return func(*args, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/contrib/admin/options.py" in add_view
955. self.save_model(request, new_object, form, False)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django_pencil/admin.py" in save_model
52. super(PictureAdmin, self).save_model(request, obj, form, change)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/contrib/admin/options.py" in save_model
709. obj.save()
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/query.py" in insert_query
1576. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
909. for sql, params in self.as_sql():
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/sql/compiler.py" in as_sql
872. for obj in self.query.objs
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/fields/files.py" in pre_save
249. file.save(file.name, file, save=False)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django_resized/forms.py" in save
31. super(ResizedImageFieldFile, self).save(name, new_content, save)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/db/models/fields/files.py" in save
86. self.name = self.storage.save(name, content)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/core/files/storage.py" in save
44. name = self.get_available_name(name)
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/core/files/storage.py" in get_available_name
70. while self.exists(name):
File "/home/myproject/myproject.com/python/lib/python2.5/site-packages/django/core/files/storage.py" in exists
230. return os.path.exists(self.path(name))
File "/usr/lib/python2.5/posixpath.py" in exists
171. st = os.stat(path)
Exception Type: UnicodeEncodeError at /admin/django_pencil/picture/add/
Exception Value: 'ascii' codec can't encode characters in position 58-65: ordinal not in range(128)
最佳答案
同时添加到django.wsgi:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
简单的 sys.setdefaultencoding('utf-8') 无济于事,重新加载很重要这是 python 2.x 的问题,不是 django
关于Django UnicodeEncodeError,在 Debian lenny 上带有 mod_wsgi 的 Apache2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12761139/
我在安装 java 后在 Debian Lenny 上安装了 Eclipse (apt-get install sun-java6-jre sun-java6-plugin sun-java6-jdk
嘿, 尝试将 qooxdoo 与 debian lenny 一起使用。qooxdoo SDK 1.2 create-application.py 好的,但我在generate.py 上遇到了问题: /
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我正在尝试在我的 debian - lenny 上编译 VXI11 源代码,但出现此错误: make rpcgen -M vxi11.x make: rpcgen: command not found
如果世界上某个地方已经有这个问题的答案,请提前道歉,但我已经花了 3 小时尝试将它安装到我的生产服务器中,但我没有任何进展。 我的需求: 我想在我的服务器上运行 git 命令(例如:推送、提交等)。为
在 OpenSuse 11.2 上,我成功编译、链接并运行了以下代码,该代码使用 unixODBC 为 MySQL 数据库安装了数据源: #include #include #include #
我在一些服务器上安装的 Python (2.6) 编译时没有我现在需要的 curses 支持,尽管服务器安装了 libncurses5,Python 没有为它编译绑定(bind),所以当我“导入 cu
我正在 Debian Lenny 上从源代码构建 python2.6。 (./configure make make altinstall) 我不希望它与现有的任何东西发生冲突,但我希望它位于 bas
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
短篇小说: 我需要 sqlite3 的 >3.7.3 版本,但我目前有 3.5.?。如何升级软件包? 长话短说: 尝试安装 etherpad-lite(etherpad 的 node.js 实现)。由
我尝试通过下载源代码并执行以下命令安装pycrypto模块python setup.py install,然后出现错误 running install running build running bu
我在生产服务器上遇到 unicode 文件名问题。当我尝试保存文件时,发生 UnicodeEncodeError 异常。 Devserver 工作正常。 www-data 的所有语言环境都是“en_U
保留问答环节: 我在使用最新 (v.2.4.2) OpenCV 版本时遇到了一个奇怪的问题,安装失败并出现以下错误: In file included from /OpenCV-2.4.2/modul
我正在使用 Selenium 测试我的网站,它使用 Firefox 打开一个 URL,登录并在页面上做一些事情,然后注销并关闭 Firefox。这一切在 Windows 7 上运行良好。代码以: We
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我按照 node.js wiki 中的说明安装了 node.js。所以我将 debian sid 源放在我的源列表中并安装了 Node 。之后,我使用 wiki 站点的 curl cmd 安装了 np
我想在我的 php ini 文件中关闭生产环境中的 display_errors,并将错误保存在日志文件中。在尝试了几个小时都没有成功之后,我决定征求建议。 我做了什么: 在根据php信息加载的ini
我试过了 apt-get update 在 Debian Lenny 上,但出现以下错误。如何解决此问题以便可以安装 PostgreSql 9.1? root:~# apt-get update Ig
我正在尝试通过 NPM 在 Debian Lenny (5.0) 上永久安装,但我在安装过程中收到以下错误,开头为: > node-waf configure build npm ERR! TypeE
我想用 XtraDB 将我的 Debian Lenny 32 位服务器上的 MySQL 5.1 替换为 Percona Server。主要原因是 Percona 的性能更好。 它是运行着许多服务的生产
我是一名优秀的程序员,十分优秀!