Fedora 39 にアップグレードすると、Flaskが動作しなくなった
Fedora39 にアップグレードすると、mod_wsgi で起動している Flask が動作しなくなった。
ログ確認
[Sun Nov 19 19:54:50.397766 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] mod_wsgi (pid=19057): Failed to exec Python script file '/var/www/wsgi/application.wsgi'. [Sun Nov 19 19:54:50.397982 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] mod_wsgi (pid=19057): Exception occurred processing WSGI script '/var/www/wsgi/application.wsgi'. [Sun Nov 19 19:54:50.399568 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] Traceback (most recent call last): [Sun Nov 19 19:54:50.400068 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/var/www/wsgi/application.wsgi", line 7, in <module> [Sun Nov 19 19:54:50.400130 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] from WebApp import app as application [Sun Nov 19 19:54:50.400167 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/var/www/wsgi/WebApp/__init__.py", line 10, in <module> [Sun Nov 19 19:54:50.400183 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] app = Flask(__name__) [Sun Nov 19 19:54:50.400196 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] ^^^^^^^^^^^^^^^ [Sun Nov 19 19:54:50.400226 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/usr/lib/python3.12/site-packages/flask/app.py", line 709, in __init__ [Sun Nov 19 19:54:50.400258 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/usr/lib/python3.12/site-packages/flask/scaffold.py", line 50, in wrapper_func [Sun Nov 19 19:54:50.400329 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/usr/lib/python3.12/site-packages/flask/app.py", line 1357, in add_url_rule [Sun Nov 19 19:54:50.400363 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/usr/lib/python3.12/site-packages/werkzeug/routing/map.py", line 174, in add [Sun Nov 19 19:54:50.400396 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/usr/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 560, in bind [Sun Nov 19 19:54:50.400429 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] File "/usr/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 688, in compile [Sun Nov 19 19:54:50.400480 2023] [wsgi:error] [pid 19057:tid 19108] [client 192.168.3.6:46690] TypeError: RulePart() takes no arguments [Sun Nov 19 19:54:50.990034 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] mod_wsgi (pid=18851): Failed to exec Python script file '/var/www/wsgi/application.wsgi'., referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.990215 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] mod_wsgi (pid=18851): Exception occurred processing WSGI script '/var/www/wsgi/application.wsgi'., referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.993882 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] Traceback (most recent call last):, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994709 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/var/www/wsgi/application.wsgi", line 7, in <module>, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994767 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] from WebApp import app as application, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994802 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/var/www/wsgi/WebApp/__init__.py", line 10, in <module>, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994837 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] app = Flask(__name__), referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994851 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] ^^^^^^^^^^^^^^^, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994883 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 253, in __init__, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994900 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] self.add_url_rule(, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994949 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/usr/local/lib/python3.12/site-packages/flask/sansio/scaffold.py", line 44, in wrapper_func, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994966 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] return f(self, *args, **kwargs), referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.994979 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] ^^^^^^^^^^^^^^^^^^^^^^^^, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995008 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/usr/local/lib/python3.12/site-packages/flask/sansio/app.py", line 655, in add_url_rule, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995024 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] self.url_map.add(rule), referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995053 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/usr/local/lib/python3.12/site-packages/werkzeug/routing/map.py", line 169, in add, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995105 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] rule.bind(self), referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995137 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/usr/local/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 563, in bind, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995154 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] self.compile(), referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995183 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] File "/usr/local/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 694, in compile, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995201 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] RulePart(, referer: https://wsgi.magic-object.page/htmlToPNG [Sun Nov 19 19:54:50.995257 2023] [wsgi:error] [pid 18851:tid 19016] [client 192.168.3.6:46704] TypeError: RulePart() takes no arguments, referer: https://wsgi.magic-object.page/htmlToPNG
原因
は? 「app = Flask(__name__)」でエラー? しかも直接的な原因が「TypeError: RulePart() takes no arguments」だと?
確認
問題の箇所のソースを確認すると、どうやら「@dataclass」が正しく認識されていない様だった。
Python のバージョンが上がった事に関する問題だろうか?
現況確認
どうやら「mod_wsgi」で Python 3.12 を動作させるには、設定を変更する必要があるらしい。
mod_wsgi の GitHub で確認すると、Python側の問題でバグではないとの事。
さらに調べていくと、mod_wsgi のパラメータを変更する事で解決するらしい。
Apache の設定を変更
WSGIApplicationGroup %{GLOBAL}
Apache を再起動
# systemctrl restart httpd
動作確認
問題なく起動するようになった。この問題はFlaskだけではなくDjango でも発生する事があるそうだ。