Python 3.4 mod_wsgiアプリケーションサーバーが例外をスローしたときにブラウザにトレースバックを表示するために、Python Paste 2.0.3に含まれるErrorMiddlewareを使用しようとしています。Python 3 mod_wsgiアプリケーションでErrorMiddlewareを貼り付けると例外がスローされるのはなぜですか?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/paste/exceptions/errormiddleware.py", line 154, in __call__
response = self.exception_handler(exc_info, environ)
File "/usr/lib/python3.4/site-packages/paste/exceptions/errormiddleware.py", line 188, in exception_handler
simple_html_error=simple_html_error)
File "/usr/lib/python3.4/site-packages/paste/exceptions/errormiddleware.py", line 391, in handle_exception
error_stream.write(line)
TypeError: must be str, not bytes
ので、私はまだちょうどブラウザで500 Internal Server Error
を取得しています:私が午前問題は、それが私のサーバーの例外を処理しようとするたびErrorMiddlewareは、この例外をスローしていることです。
問題がErrorMiddlewareはWSGIエラーストリームにバイトを書き込みしようとしていることのようだ:
if six.PY3:
line = line.encode('utf8')
error_stream.write(line) # line 391 error_stream comes from environ['wsgi.errors']
が、私はenviron['wsgi.errors']
をプリントアウトした場合、それはテキストストリームのように見える:
'wsgi.errors': <_io.TextIOWrapper name='<wsgi.errors>' encoding='utf-8'>
これは、ErrorMiddlewareがバイトを書き込むことができないことを意味します。
私はこのようErrorMiddlewareで自分のアプリケーションをラップしています:
application = ErrorMiddleware(application, debug=True)
はこれを引き起こす私が間違っているの何かがありますか?エラーストリームがテキストストリームではなくバイトストリームになるようにmod_wsgiを設定できますか?
でバイトを書き込もうとすることを間違って見えます。確認していただきありがとうございます。 – gla3dr