Flask application deploy error

Asked

Viewed 35 times

0

I am trying to deploy a flask application in the same way I do when using python2.7, but in this case I am using python3 and an error is returned in wsgi. Below follows the first line of apache2 traceback.

[Thu Dec 06 23:01:04.823744 2018] [wsgi:error] [pid 21968:tid 139980181575424] [client 189.127.245.17:55892] mod_wsgi (pid=21968): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.

I installed the required Packages correctly, including the libapache2-mod-wsgi-py3 who I believe is right for Python3.

Flaskapp.conf

<VirtualHost *:80>
  ServerName ip-do-servidor
  ServerAdmin admin-do-servidor
  WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
  <Directory /var/www/FlaskApp/FlaskApp/>
      Order allow,deny
      Allow from all
  </Directory>
  Alias /static /var/www/FlaskApp/FlaskApp/static
  <Directory /var/www/FlaskApp/FlaskApp/static/>
      Order allow,deny
      Allow from all
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

flaskapp.wsgi

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = 'super_secret_key'
  • Check which standard version of Python on the system, it might be loading version 2.7 by default instead of 3.x.

  • You are using the correct version, python3.6

  • For Python3.6+ you need to use mod_wsgi_python3.6.so. If you need help setting up take a look therein

1 answer

0

I was able to fix, the error was in my application and not in wsgi itself, I was able to visualize the correct error after going down to the last line of apache error.log.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.