gpt4 book ai didi

Django utf-8 网址

转载 作者:行者123 更新时间:2023-12-03 22:04:49 29 4
gpt4 key购买 nike

我有一个 Django 应用程序,它可以在 localhost 上正常工作。即使对于 utf-8 URL 路径也是如此。但是当我在生产中使用它时,它给了我一个错误:

2019-09-01 14:32:09.558237 [ERROR] [12257] wsgiAppHandler pApp->start_response() return NULL.
Traceback (most recent call last):
File "/home/medualla/virtualenv/project/3.7/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 139, in call
set_script_prefix(get_script_name(environ))
File "/home/medualla/virtualenv/project/3.7/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 179, in get_script_name
script_url = get_bytes_from_wsgi(environ, 'SCRIPT_URL', '') or get_bytes_from_wsgi(environ, 'REDIRECT_URL', '')
File "/home/medualla/virtualenv/project/3.7/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 204, in get_bytes_from_wsgi
return value.encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-6: ordinal not in range(256)

当我尝试像这样的网址时会发生此错误
http://meduallameh.ir/صفحه
我得到的唯一答案是网络服务器的问题。我将它部署在共享主机上并询问他们,他们告诉我 Web 服务器支持 utf-8。现在我需要一些帮助来解决这个问题。

最佳答案

在处理了一些代码并搜索了问题之后,我发现问题在于 SCRIPT_URL 和其他内容在主机中默认解码为 utf-8。所以它给出了一个错误。我通过将 get_bytes_from_wsgi 返回语句更改为这个来临时修复它;

def get_bytes_from_wsgi(environ, key, default):
"""
Get a value from the WSGI environ dictionary as bytes.

key and default should be strings.
"""
value = environ.get(key, default)
# Non-ASCII values in the WSGI environ are arbitrarily decoded with
# ISO-8859-1. This is wrong for Django websites where UTF-8 is the default.
# Re-encode to recover the original bytestring.
return value.encode('utf-8')

所以问题解决了(暂时)。我发现这种情况发生在许多标题上,尤其是文件中。如果有人找到另一种可以解决的方法,请写在这里

关于Django utf-8 网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57754478/

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