Below is a snip of the app code. I didn't think it was relevant as the page
doesn't even load, i.e., before the submit. And since I got it working with
mod_wsgi-express start-server I thought it had to be something in the
httpd.conf file.
from flask import Flask, render_template, request, redirect, url_for,
make_response,jsonify
from werkzeug.utils import secure_filename
import os
import cv2
import time
from scipy import ndimage
from datetime import timedelta
import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
import nilearn
from nilearn import plotting
from nilearn import image
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'JPG', 'PNG', 'bmp','nii.gz','nii'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 2)[1] in
ALLOWED_EXTENSIONS
app = Flask(__name__)
app.send_file_max_age_default = timedelta(seconds=1)
def show_slices(slices):
""" Function to display row of image slices """
fig, axes = plt.subplots(1, len(slices))
for i, slice in enumerate(slices):
axes[i].imshow(slice.T, cmap="gray", origin="lower")
# @app.route('/upload', methods=['POST', 'GET'])
@app.route('/upload', methods=['POST', 'GET'])
def upload():
if request.method == 'POST':
f = request.files['file']
if not (f and allowed_file(f.filename)):
return jsonify({"error": 1001, "msg": "png,PNG,jpg,JPG,bmp"})
user_input = request.form.get("name")
user_input1 = request.form.get("name1")
user_input2 = request.form.get("name2")
a = int(user_input)
b = int(user_input1)
c = int(user_input2)
basepath = os.path.dirname(__file__)
upload_path = os.path.join(basepath, 'static/images',
secure_filename(f.filename))
# upload_path = os.path.join(basepath, 'static/images','test.jpg')
f.save(upload_path)
epi_img = nib.load(upload_path)
epi_img_data = epi_img.get_fdata()
shape = epi_img_data.shape
x = shape[0] - 1
On Tuesday, October 29, 2019 at 5:18:04 PM UTC-4, Graham Dumpleton wrote:
>
> As I already asked, how is the path for where you are storing the upload
> calculated? What is the code and any configuration?
>
> On 30 Oct 2019, at 6:59 am, Robert Kudyba <[email protected]
> <javascript:>> wrote:
>
> SELinux is definitely disabled. When I test the app locally, all works
> well. I also found where you made a suggestion
> <https://davidhamann.de/2017/08/05/running-flask-with-wsgi-on-macos/> to
> try mod_wsgi-express start-server, and that works fine, and the URL
> displays and the image upload works:
>
> # mod_wsgi-express-3 setup-server upload_pictures.wsgi --port=8987 --user
> my --group mygroup
> Server URL : http://localhost:8987/
> Server Root : /tmp/mod_wsgi-localhost:8987:0
> Server Conf : /tmp/mod_wsgi-localhost:8987:0/httpd.conf
> Error Log File : /tmp/mod_wsgi-localhost:8987:0/error_log (warn)
> Rewrite Rules : /tmp/mod_wsgi-localhost:8987:0/rewrite.conf
> Environ Variables : /tmp/mod_wsgi-localhost:8987:0/envvars
> Control Script : /tmp/mod_wsgi-localhost:8987:0/apachectl
> Request Capacity : 5 (1 process * 5 threads)
> Request Timeout : 60 (seconds)
> Startup Timeout : 15 (seconds)
> Queue Backlog : 100 (connections)
> Queue Timeout : 45 (seconds)
> Server Capacity : 20 (event/worker), 20 (prefork)
> Server Backlog : 500 (connections)
> Locale Setting : en_US.UTF-8
>
> /tmp/mod_wsgi-localhost:8987:0/apachectl start
>
> So perhaps my stanza in the httpd.conf is awry?
>
> On Tuesday, October 29, 2019 at 3:32:14 PM UTC-4, Graham Dumpleton wrote:
>>
>> Where are you defining the path to upload images to? It cannot be a
>> relative path, you need to calculate it as an absolute path. See:
>>
>>
>> https://modwsgi.readthedocs.io/en/develop/user-guides/application-issues.html#application-working-directory
>>
>> Only other thing off top of my head that could be is that have SELinux
>> enabled and it is blocking where you are writing to.
>>
>> It is hard to guess without see any error message, but looks like you
>> don't have Flask configured to log error messages and they get swallowed up.
>>
>> Graham
>>
>> On 30 Oct 2019, at 2:50 am, Robert Kudyba <[email protected]> wrote:
>>
>> Running Apache/2.4.41 on Fedora 30 and
>> python3-mod_wsgi-4.6.4-3.fc30.x86_64. And doing a test with:
>> mod_wsgi-express
>> start-server /var/www/flask/upload_pictures.wsgi --user myuser works
>> mostly fine just uses Python 2.7 and some warnings. Browsing the URL works
>> fine. The app just allows users to upload a picture.
>>
>> [Tue Oct 29 10:05:05.365111 2019] [mpm_event:notice] [pid 17160:tid
>> 140276832493888] AH00489: Apache/2.4.41 (Fedora) mod_wsgi/4.6.4 Python/2.7
>> configured -- resuming normal operations
>> [Tue Oct 29 10:05:05.365167 2019] [core:notice] [pid 17160:tid
>> 140276832493888] AH00094: Command line: 'httpd (mod_wsgi-express) -f
>> /tmp/mod_wsgi-localhost:8000:16836/httpd.conf -D
>> MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D
>> MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D
>> FOREGROUND'
>> [Tue Oct 29 10:05:05.809860 2019] [wsgi:error] [pid 17162:tid
>> 140276832493888] /usr/lib/python2.7/site-packages/nilearn/__init__.py:73:
>> DeprecationWarning: Python2 support is deprecated and will be removed in the
>> next release. Consider switching to Python 3.6 or 3.7.
>> [Tue Oct 29 10:05:05.809882 2019] [wsgi:error] [pid 17162:tid
>> 140276832493888] _python_deprecation_warnings()
>> [Tue Oct 29 10:05:38.461053 2019] [mpm_event:notice] [pid 17160:tid
>> 140276832493888] AH00491: caught SIGTERM, shutting down
>> [Tue Oct 29 10:05:41.124861 2019] [mpm_event:notice] [pid 17414:tid
>> 140153494917440] AH00489: Apache/2.4.41 (Fedora) mod_wsgi/4.6.4 Python/2.7
>> configured -- resuming normal operations
>> [Tue Oct 29 10:05:41.124923 2019] [core:notice] [pid 17414:tid
>> 140153494917440] AH00094: Command line: 'httpd (mod_wsgi-express) -f
>> /tmp/mod_wsgi-localhost:8000:16836/httpd.conf -D
>> MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D
>> MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D
>> FOREGROUND'
>> [Tue Oct 29 10:05:41.598057 2019] [wsgi:error] [pid 17417:tid
>> 140153494917440] /usr/lib/python2.7/site-packages/nilearn/__init__.py:73:
>> DeprecationWarning: Python2 support is deprecated and will be removed in the
>> next release. Consider switching to Python 3.6 or 3.7.
>> [Tue Oct 29 10:05:41.598077 2019] [wsgi:error] [pid 17417:tid
>> 140153494917440] _python_deprecation_warnings()
>>
>> Here is what is in the upload_pictures.wsgi file:
>>
>> #!/usr/local/bin/anaconda3/bin/python3
>> import sys
>> import logging
>> logging.basicConfig(stream=sys.stderr)
>>
>> sys.path.insert(0, '/home/myhome/myuser/public_html')
>>
>> from upload_pictures2 import app as application
>>
>> application.root_path = '/home/myhome/myuser/public_html'
>>
>> And here is what's in the end of the httpd.conf file:
>>
>> <VirtualHost *:8000>
>> WSGIDaemonProcess upload_pictures2 user=apache group=apache threads=5
>> WSGIScriptAlias / /var/www/flask/upload_pictures.wsgi
>>
>> <Directory /home/myhome/myuser/public_html>
>> WSGIProcessGroup upload_pictures2
>> WSGIApplicationGroup %{GLOBAL}
>> WSGIScriptReloading On
>> Order deny,allow
>> Allow from all
>> </Directory>
>> </VirtualHost>
>>
>> I've looked at similar issues here
>> <https://serverfault.com/questions/967882/uploading-a-python-flask-app-to-an-existing-apache2-server-and-making-it-listen>
>> and here
>> <https://stackoverflow.com/questions/41966855/possible-to-run-a-flask-app-with-mod-wsgi-on-a-specific-port>,
>>
>> but those don't appear to be related to my issue. I don't see any errors in
>> the logs, and netstat -ln|grep 8000 does not show port 8000 in use. Do I
>> have a problem with the paths?
>>
>> Here are the only logs that printed:
>>
>> [Tue Oct 29 10:29:47.742916 2019] [wsgi:info] [pid 26598:tid
>> 140684965835072] mod_wsgi (pid=26598): Attach interpreter ''.
>> [Tue Oct 29 10:29:47.746480 2019] [wsgi:info] [pid 26598:tid
>> 140684965835072] mod_wsgi (pid=26598): Imported 'mod_wsgi'.
>> [Tue Oct 29 10:29:47.746798 2019] [wsgi:debug] [pid 26598:tid
>> 140684920149760] src/server
>>
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/modwsgi/cb069c88-5af3-44ac-9fa4-28586a231264%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/modwsgi/cb069c88-5af3-44ac-9fa4-28586a231264%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>>
> --
> 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 [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/modwsgi/5d2ebb75-aeb9-4c50-8462-60246aed3965%40googlegroups.com
>
> <https://groups.google.com/d/msgid/modwsgi/5d2ebb75-aeb9-4c50-8462-60246aed3965%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/modwsgi/45c34fca-e907-4b87-bad4-3ab81e5962bd%40googlegroups.com.