1

I have a flask application that is serving through apache/mod_wsgi and running on a Docker container which is running on AWS-EC2 Ubuntu 16.04 server instance.

The error which I am getting is:

[Wed Mar 27 10:08:55.430668 2019] [mpm_event:notice] [pid 6:tid 139857176496000] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.6.5 Python/2.7 configured -- resuming normal operations
[Wed Mar 27 10:08:55.430783 2019] [core:notice] [pid 6:tid 139857176496000] AH00094: Command line: 'apache2 (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:9090:999/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'
[Wed Mar 27 10:08:55.443834 2019] [wsgi:error] [pid 8:tid 139857176496000] mod_wsgi (pid=8): Failed to exec Python script file '/tmp/mod_wsgi-localhost:9090:999/handler.wsgi'.
[Wed Mar 27 10:08:55.443868 2019] [wsgi:error] [pid 8:tid 139857176496000] mod_wsgi (pid=8): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:9090:999/handler.wsgi'.
[Wed Mar 27 10:08:55.443886 2019] [wsgi:error] [pid 8:tid 139857176496000] Traceback (most recent call last):
[Wed Mar 27 10:08:55.443901 2019] [wsgi:error] [pid 8:tid 139857176496000]   File "/tmp/mod_wsgi-localhost:9090:999/handler.wsgi", line 5, in <module>
[Wed Mar 27 10:08:55.443968 2019] [wsgi:error] [pid 8:tid 139857176496000]     import time
[Wed Mar 27 10:08:55.443985 2019] [wsgi:error] [pid 8:tid 139857176496000] ImportError: No module named time

This is my mod_wsgi file:

#! /usr/bin/python2.7

import sys
import os

##Add this file path to sys.path in order to import settings
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '../..'))
sys.path = ['/usr/lib/python2.7', '/usr/local/lib/python2.7']

##Add this file path to sys.path in order to import app
sys.path.insert(0, "/home/niramai/application/")

##Create an application for our app
from postProcessing_flask import app as application

This is my apache configuration settings:

WSGIScriptAlias /postProcess /home/niramai/application/postProcessing_flask.wsgi
WSGIScriptReloading On
WSGIDaemonProcess website processes=2 threads=15 display-name=%{GROUP} python-path=/home/niramai/application/

<Directory /home/niramai/application>
  Order allow,deny
  Allow from all
</Directory>

This is my Dockerfile, the docker image is built on paraview-osmesa image which cmakes paraview-osmesa:

ARG BASE_IMAGE=kitware/paraviewweb:pv-osmesa-v5.6.0 
FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/paraview/install/lib/:/usr/lib/python2.7

USER root
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y \
    python2.7 \
    python-pip \
    python2.7-dev \
    lsof \
    apache2 \
    apache2-dev \
    vim \
    libapache2-mod-wsgi 

# pip install necesary python packages
RUN pip2 install \
            Flask \
            flask-restful \
            boto3 \
            requests \
            mod_wsgi \
        times


###################################################################################
# Start dumb_init as pid 1, to prevent any weird behaviour.
ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.1/dumb-init_1.1.1_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

# Default user is root, which could cause issues in case of a breakout.
RUN groupadd -r niramai && useradd -m -r -g niramai niramai

COPY paraview-wsgi.conf /etc/apache2/conf-enabled/

RUN service apache2 restart

RUN mkdir -p /home/niramai/application

WORKDIR /home/niramai/application

RUN ln -fs /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.py /usr/lib/python2.7/

USER niramai

COPY --chown=niramai:niramai . .

EXPOSE 9090

CMD ["dumb-init", "mod_wsgi-express", "start-server", "postProcessing_flask.wsgi", "--port", "9090", "--socket-timeout", "600" ]

I have tried adding python path to the WSGIDaemonProcess, tried appending sys.path to include the python libraries.

Tried changing the permissions to the folders by setting group's setgid (the lower case "s") by using "chmod u+s postProcessing_flask.wsgi".

Tried appending the LD_LIBRARY_PATH and exclusively setting PYTHONPATH in mod_wsgi-express start-server command, but none of them worked.

I am new to this domain and any help would be greatly appreciated.

  • A good first step would be to try to reproduce this same situation outside of Python. Can you run the same script under, say, gunicorn? Does it produce the same error? (The explicit setting of `sys.path` doesn't look right to me.) – David Maze Mar 27 '19 at 10:48
  • Thank you for your comment and sorry for a very late reply. Thanks to Graham Dumpleton I understood that I was missing/lost a C extension module which contained the time module. I updated python 2.7 to python 3.6 and it solved the issue. – Shailesh Bg Apr 05 '19 at 10:38

0 Answers0