Django,openshi上的python nonascii字符

2024-10-01 00:19:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在openshift中有一个django1.5,python2.7应用程序,我得到了一个djangunicodedecodeError,它包含非ascii字符,比如ç,á。。在

我花了几个小时来解决这个问题(我是python、django和openshift中的begginer)

它不是在本地发生的,只是在openshift云服务器上。

有没有办法通过ssh解决这个问题?或者其他的。。在

这是打印堆栈:

Request Method: POST

Request URL: ----

Django Version: 1.5

Exception Type: DjangoUnicodeDecodeError

Exception Value:
'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128). You passed in <django.utils.functional.proxy object at 0x7f10ccfde9d0> ()
Exception Location: /var/lib/openshift/.../python/virtenv/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/utils/encoding.py in force_text, line 115

Python Executable: /var/lib/openshift/.../python//virtenv/bin/python

Python Version: 2.7.5

Python Path:...

谢谢

罗伯托。在


Tags: djangoin应用程序versionrequestvarlibascii
1条回答
网友
1楼 · 发布于 2024-10-01 00:19:25

我最近在我的机器上遇到了类似的问题,我使用unicode文字+智能文本解决了这个问题:

from __future__ import unicode_literals
from django.utils.encoding import smart_text


safeText = smart_text('this is my tetxt : %s' % someVaribleHoldingTextData)

或者,您可能需要将从文件读取的数据解码为特定的字符集:

^{pr2}$

编码是一个很难的话题…你必须尝试,然后再试一次:p

相关问题 更多 >