gpt4 book ai didi

python - Linux Only 'ascii' 编解码器无法对位置 3 : ordinal not in range(128) 中的字符 u'\u0161' 进行编码

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:21 26 4
gpt4 key购买 nike

我遇到了一个错误,这只发生在 linux 服务器上,apache2 在 django 上运行 wsgi。我在 Windows 中进行开发,然后将其复制到 Linux 服务器。

我看到问题出在字符串中:(粗体部分是Django标记的)

Društvo tabornikov - Rod Srnjak Logatec

但是这个错误只发生在一页上。设置页面上也使用了相同的字符串,但它显示正确。同样的错误也会出现在管理页面上。在 views.py 文件中我已经设置了 utf-8 编码。如果我在没有 apache 的情况下启动服务器,则不会发生错误:

 python3 manage.py runserver 0.0.0.0:8000

跟踪:

Environment:


Request Method: GET
Request URL: https://***.***.**/vodnik/eposta/?cid=17

Django Version: 1.10.3
Python Version: 2.7.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'vodnik',
'schedule',
'djangobower']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template /var/www/etaborniki/templates/vodnik/eposta.html, error at line 59
ascii 49 : <small style="text-align: justify"><strong>Opomba:</strong> Na dno sporočila bodo avtomatsko dodani podatki roda in
50 : obrazložitev namena
51 : sporočila, ker je naša aplikacija skladna z zakonom <a href="https://www.uradni-list.si/1/content?id=111442">ZEKom-1</a>.
52 : </small>
53 : <br/>
54 : <small style="text-align: justify"><strong>Soglasje:</strong> S pritiskom na gumb pošlji se z navedenim popolnoma
55 : strinjam in prevzemam vso
56 : odgovornost. V sporočilu ne smem posredovati kakršnihkoli osebnih podatkov, sovražnega govora ali vsiljene
57 : pošte. Strinjam se, da bo moj e-naslov razviden prejemniku in družbi KSoft.Si. Sporočila se hranijo do 3 mesece.
58 : Kršitev tega soglasja ali zakonov ZEKom-1, ZEPT in ZVOP-1, se lahko sodno preganja. Za katerokoli kršitev družba
59 : KSoft.Si in {{ rod_ime }} ne odgovarjata.
60 : </small>
61 : </div>
62 :
63 : {% include 'generic/scripts.html' %}
64 : {% include 'generic/tinymce.html' %}
65 : </body>
66 : </html>
67 :

Traceback:

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)

File "/var/www/etaborniki/vodnik/views.py" in eposta
177. return render_to_response('vodnik/eposta.html', c)

File "/usr/local/lib/python3.5/dist-packages/django/shortcuts.py" in render_to_response
21. content = loader.render_to_string(template_name, context, using=using)

File "/usr/local/lib/python3.5/dist-packages/django/template/loader.py" in render_to_string
68. return template.render(context, request)

File "/usr/local/lib/python3.5/dist-packages/django/template/backends/django.py" in render
66. return self.template.render(context)

File "/usr/local/lib/python3.5/dist-packages/django/template/base.py" in render
208. return self._render(context)

File "/usr/local/lib/python3.5/dist-packages/django/template/base.py" in _render
199. return self.nodelist.render(context)

File "/usr/local/lib/python3.5/dist-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/usr/local/lib/python3.5/dist-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/usr/local/lib/python3.5/dist-packages/django/template/base.py" in render
1050. return render_value_in_context(output, context)

File "/usr/local/lib/python3.5/dist-packages/django/template/base.py" in render_value_in_context
1028. value = force_text(value)

File "/usr/local/lib/python3.5/dist-packages/django/utils/encoding.py" in force_text
80. s = six.text_type(bytes(s), encoding, errors)

Exception Type: UnicodeEncodeError at /vodnik/eposta/
Exception Value: 'ascii' codec can't encode character u'\u0161' in position 3: ordinal not in range(128)

最佳答案

错误表明你有 python 2.7 active

...

Django Version: 1.10.3
Python Version: 2.7.12
Installed Applications:
...

因此,由于您似乎使用 python3 运行开发服务器,我假设您希望对实时版本执行相同的操作。

关于python - Linux Only 'ascii' 编解码器无法对位置 3 : ordinal not in range(128) 中的字符 u'\u0161' 进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40441355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com