RHEL 7 mod_wsgi s.bind Permission denied errors

14 views
Skip to first unread message

Jeremy Hawkins

unread,
Aug 16, 2019, 2:18:00 AM8/16/19
to modwsgi
I am trying to run a flask app as a script with Apache 2.4 under a Red Hat Enterprise Linux 7.6

I got the app to the point where it will run if a do use python app.wsgi (within that directory).

When I try to run it from apach using the mod_wsgi I get the following errors in the logs.

I have tried everything that I can run across to try to resolve this issue.  I am at a lost to even figure what is actually causing this issue.


Error Log:
mod_wsgi (pid=4159): Exception occurred processing WSGI script '/var/projects/janus/app.wsgi'.
Traceback (most recent call last):
File "/var/projects/janus/app.wsgi", line 11, in <module>
app.run(host="0.0.0.0")
File "/var/projects/janus/venv/lib/python3.6/site-packages/flask/app.py", line 990, in run
run_simple(host, port, self, **options)
File "/var/projects/janus/venv/lib/python3.6/site-packages/werkzeug/serving.py", line 987, in run_simple
s.bind(server_address)
PermissionError: [Errno 13] Permission denied

Graham Dumpleton

unread,
Aug 16, 2019, 2:21:16 AM8/16/19
to mod...@googlegroups.com
You shouldn't be invoking app.run() when hosting under mod_wsgi as that is trying to start its own server.

You should use a check like:

    if __name__ == "__main__":
        ....

around the parts of the Flask code where the Flask development server is started so that it isn't run when that file is imported in a context other than being a main program.

What mod_wsgi is expecting is a WSGI application entry point called "application". See:


--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/6ffd7529-a989-45de-9ce3-5b3466915623%40googlegroups.com.

Jeremy Hawkins

unread,
Aug 16, 2019, 4:14:11 PM8/16/19
to modwsgi
Thank you.  Removing the app.run() and changing the app to application (using a factory so changed app = create_app() --> application = create_app())

Now when running the site via apache the post requests don't seem to be running.  They all return the http code of 302 (found) instead of 200 like they do when I run the app directly in python.  I am not seeing any errors in any logs and the path the post is using is being formed correctly by the url_for function.  I'd almost say the post request aren't passing data to the wsgi application?
To unsubscribe from this group and stop receiving emails from it, send an email to mod...@googlegroups.com.

Graham Dumpleton

unread,
Aug 16, 2019, 5:24:33 PM8/16/19
to mod...@googlegroups.com
At what sub path to the site are the post requests being targeted?

Sounds more like you have an issue where handler is at /subpath/, but you are using /subpath, and so trailing slash redirection is being tripped.

What does the Location header in responses say?

How do you have WSGIScriptAlias set in the Apache config?

To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/103fd512-f17f-40ab-8744-01972ca81aee%40googlegroups.com.

Jay Rat

unread,
Aug 16, 2019, 6:01:24 PM8/16/19
to mod...@googlegroups.com
The http response is 302.  

Using blueprints. For the posts the end point is admin/faculty/<id> 
I added a logger into that method and the logger statement at the front of the method runs bit the statements in the form processing sections never run 

Graham Dumpleton

unread,
Aug 16, 2019, 7:40:42 PM8/16/19
to mod...@googlegroups.com
You didn't answer my other questions.

What does the Location header in responses say?

How do you have WSGIScriptAlias set in the Apache config?

Jay Rat

unread,
Aug 16, 2019, 8:32:20 PM8/16/19
to mod...@googlegroups.com
The alias in the Apache config I'll have to look at monday. Think its /online but cant recall of there is at the end or not

Jeremy Hawkins

unread,
Aug 19, 2019, 11:42:47 AM8/19/19
to modwsgi
The alias is at /online
WSGIScriptAlias /online /var/projects/janus/app.wsgi

Graham Dumpleton

unread,
Aug 19, 2019, 9:15:34 PM8/19/19
to mod...@googlegroups.com
And what was the original URL the POST request was made against?

How is the Flask handler defined which is meant to handle the URL for the POST request?

To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/5a63b002-4532-4505-b55a-5d9fc25092e1%40googlegroups.com.

Jeremy Hawkins

unread,
Aug 20, 2019, 10:34:29 AM8/20/19
to modwsgi
I hope this is what you're asking for.

The form is in a dialog inside of a page that is located at online/admin/faculty/<id>
the form action is set to {{url_for('admin.update_faculty', id=faculty.facultyno)}} which converts to /online/admin/faculty/<id> and the method is post.

The headers for the request is:

  1. Request URL:
  2. Request Method:
    POST
The location is the response header is:
Location:


The url rules for both of these locations are:


blueprint.add_url_rule(
'/faculty/<id>', endpoint='get_faculty', view_func=get_faculty)

blueprint.add_url_rule('/faculty/<id>', endpoint='update_faculty',
view_func=update_faculty, methods=['POST'])

The update_faculty does end with a return redirect(url_for('admin.get_faculty',id=id))
I am wondering if this is the reason the response code is 302 instead of 200.
I do have logger statements at the start of the update_faculty method which runs, but additional logger statements in the method do not run.
To unsubscribe from this group and stop receiving emails from it, send an email to mod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/5a63b002-4532-4505-b55a-5d9fc25092e1%40googlegroups.com.

Jeremy Hawkins

unread,
Aug 20, 2019, 10:51:02 AM8/20/19
to modwsgi
not 100% sure why, but the issue is resolved.

I think there is an issue with the mod_wsgi not updating when changes are made to the application.
There was a change to the form to make a field optional instead of required and that change didn't seem to push through.
I finally was able to get errors from the form validation.  restarting the Apache process then testing again and it seems to be working.
To unsubscribe from this group and stop receiving emails from it, send an email to mod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/5a63b002-4532-4505-b55a-5d9fc25092e1%40googlegroups.com.

Graham Dumpleton

unread,
Aug 21, 2019, 5:43:27 AM8/21/19
to mod...@googlegroups.com
You maybe should read:


Source code is not automatically reloaded.

You can also have issues if you have .pyc file which have incorrect modification time such that they appear newer. This can arise if you copy source code and .pyc files from another system and don't preserve time stamps.

To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/fba434d8-61c1-4cd7-ba50-48f8364070ca%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages