UnicodeEncodeError:“latin1”编解码器无法对位置66中的字符u'\u03c7'进行编码:序号不在范围(256)

2024-04-23 14:35:18 发布

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

我有时会在我的网络服务器上遇到这个错误。在

Traceback (most recent call last):
File "/bin/user_wsgi_wrapper.py", line 130, in __call__
    self.error_log_file.logger.exception("Error running WSGI application")
File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
    self.error(msg, *args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
    self._log(ERROR, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
    self.threadName = threading.current_thread().name
File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
    return _active[_get_ident()]
File "/bin/user_wsgi_wrapper.py", line 122, in __call__
    app_iterator = self.app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1690, in wsgi_app
    return response(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 1082, in __call__
    app_iter, status, headers = self.get_wsgi_response(environ)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 1072, in get_wsgi_response
    return app_iter, self.status, headers.to_list()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 1141, in to_list
    for k, v in self]
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u03c7' in position 66: ordinal not in range(256)

问题是我不知道在我的代码中会发生这种情况,所以我不知道应该把.encode('utf-8','ignore')放在哪里。在


Tags: inpyselfappwsgiinitresponselib
2条回答

输入:

import pdb; pdb.set_trace()

在: 文件“/bin/user\wsgi_包装器.py“,第130行,in调用

重新启动应用程序并检查终端中的vars值。 按“n”表示“下一步”。 使用“print var_name”查看变量的值。 阅读更多信息:https://docs.python.org/2/library/pdb.html

您似乎正在尝试设置一个标头,该标头的字符不在ISO-8859-1字符集中。目前,HTTP标头必须只包含来自该编解码器的字符。更新版本的Werkzeug需要拉丁语-1编解码器,而不是更接近WSGI规范

See this Flask issue for a message about this from the maintainer.它提到使用范围外字符的正确方法在RFC 5987中描述,这可能在将来实现。在

相关问题 更多 >