mod_wsgi icon indicating copy to clipboard operation
mod_wsgi copied to clipboard

Rulepart() takes no arguments

Open kausarsabil opened this issue 3 years ago • 5 comments

i've been working on this for 2 days. i dont know why this is not working, i already followed the instruction.

folder structure: image

route.py

from flask import Flask, jsonify

app = Flask(__name__)
app.config['SECRET_KEY'] = 'asdonasfbadkjdnkasjfbnkajsdnkasfnaksjdn'

@app.get('/')
def home():
    return jsonify("hello world")

web.wsgi

import sys
sys.path.insert(0, 'D:\\app\\Python310_Project\\FlaskStart')
from apps.route import app as application

flask.conf (already Included in httpd.conf)

<VirtualHost *:80>
    ServerAdmin Flask
    ServerName *mylocalIP*:80
    AddHandler wsgi-script .wsgi
    WSGIScriptReloading On
    WSGIScriptAlias /apps "D:/app/Python310_Project/FlaskStart/wsgi/web.wsgi"

    ErrorLog "D:/app/Python310_Project/FlaskStart/wsgi/logs/error.log"
    CustomLog "D:/app/Python310_Project/FlaskStart/wsgi/logs/access.log" combined
    LogLevel debug
    
    DocumentRoot "D:/app/Python310_Project/FlaskStart"
    <Directory "D:/app/Python310_Project/FlaskStart">
            Require all granted
            Options FollowSymLinks Includes ExecCGI
    </Directory>
    
</VirtualHost>

on error.log shown:

[Sun Oct 09 16:10:12.433286 2022] [authz_core:debug] [pid 12940:tid 1252] mod_authz_core.c(815): [client 10.31.254.46:53711] AH01626: authorization result of Require all granted: granted
[Sun Oct 09 16:10:12.433286 2022] [authz_core:debug] [pid 12940:tid 1252] mod_authz_core.c(815): [client 10.31.254.46:53711] AH01626: authorization result of <RequireAny>: granted
[Sun Oct 09 16:10:12.496229 2022] [wsgi:info] [pid 12940:tid 1252] [client 10.31.254.46:53711] mod_wsgi (pid=12940, process='', application='10.31.254.46|/apps'): Loading Python script file 'D:/app/Python310_Project/FlaskStart/wsgi/web.wsgi'.
[Sun Oct 09 16:10:12.748229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711] mod_wsgi (pid=12940): Failed to exec Python script file 'D:/app/Python310_Project/FlaskStart/wsgi/web.wsgi'.
[Sun Oct 09 16:10:12.748229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711] mod_wsgi (pid=12940): Exception occurred processing WSGI script 'D:/app/Python310_Project/FlaskStart/wsgi/web.wsgi'.
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711] Traceback (most recent call last):\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:/app/Python310_Project/FlaskStart/wsgi/web.wsgi", line 8, in <module>\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     from apps.route import app as application\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310_Project\\FlaskStart\\apps\\route.py", line 4, in <module>\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     app = Flask(__name__)\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310\\lib\\site-packages\\flask\\app.py", line 709, in __init__\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     self.add_url_rule(\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310\\lib\\site-packages\\flask\\scaffold.py", line 50, in wrapper_func\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     return f(self, *args, **kwargs)\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310\\lib\\site-packages\\flask\\app.py", line 1354, in add_url_rule\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     self.url_map.add(rule)\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310\\lib\\site-packages\\werkzeug\\routing\\map.py", line 174, in add\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     rule.bind(self)\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310\\lib\\site-packages\\werkzeug\\routing\\rules.py", line 559, in bind\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     self.compile()\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]   File "D:\\app\\Python310\\lib\\site-packages\\werkzeug\\routing\\rules.py", line 667, in compile\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711]     RulePart(\r
[Sun Oct 09 16:10:12.750229 2022] [wsgi:error] [pid 12940:tid 1252] [client 10.31.254.46:53711] TypeError: RulePart() takes no arguments\r

image

how can i make this work? os == windows 11 (x64) python == 3.10 (x64) mod_wsgi == 4.9.2 tried 4.9.4 not working too (x64)

kausarsabil avatar Oct 10 '22 05:10 kausarsabil

Since this very much appears to be an issue with using Flask, rather than mod_wsgi, I suggest you ask on StackOverflow or some other forum which deals with Flask.

Also perhaps look at the Flask tutorial.

  • https://pythonbasics.org/flask-tutorial-hello-world/

In that it doesn't use @app.get('/') and instead uses @app.route('/') so maybe you just aren't defining your application properly.

GrahamDumpleton avatar Oct 10 '22 05:10 GrahamDumpleton

my flask app is working fine with app.run() from flask. i thought, it is mod_wsgi issue, so i ask here.. how about my wsgi and apache setup ? maybe i messed up with my mod_wsgi setup on apache..

kausarsabil avatar Oct 10 '22 09:10 kausarsabil

Did you make any progress on this? I still don't have any good ideas. Only thing can think of is that mod_wsgi is not setup correctly to use the same Python installation/virtual environment as is used when run on command line and what is being used has versions of Flask and Werkzeug which aren't quite compatible.

GrahamDumpleton avatar Oct 13 '22 22:10 GrahamDumpleton

I confirm the problem with combination Python 3.10 (win x64) and mod_wsgi 4.9.4 on Windows 10. Solved automatically after just upgrading to Python 3.11.2 (win x64) and compiling mod_wsgi version 4.9.4 for this version, without any other changes in web.wsgi, route.py or apache configuration files (I mean besides updating LoadFile "C:/.../Python/Python311/python311.dll", LoadModule wsgi_module "C:/.../Python/Python311/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd" and WSGIPythonHome "C:/.../Python/Python311" according to the output of mod_wsgi-express module-config) Judging from the solution, seems to be some weird bug in Flask/Python 3.10. But easy solution.

vkarantz avatar May 07 '23 10:05 vkarantz

I can also confirm that the combination of Python 3.10 (win x64) and mod_wsgi 4.9.4 on Windows 11 was causing the issue.

As mentioned by @vkarantz, I upgraded my python installation to 3.11.4 and it resolved the issue!

bhaveshnande avatar Jun 18 '23 19:06 bhaveshnande