-1

I am trying to run a Flask application on my Ubuntu server, using Apache and WSGI and Python3.8.

I started following the Flask documentation for mod_wsgi.

To setup the project, I followed the Flask tutorial from the official website.

My root lives in "/var/www/html/base/BE" and it looks like:

├── activate_this.py
├── base_be.wsgi
├── be
│   ├── __init__.py
├── be.conf
├── myenv
└── src
    ├── __init__.py
    ├── MY_SRC_FILE.py

The content of the factory function ./be/init.py is as described on the tutorial, just a "create_app" function with all my initialization.

For base_be.wsgi's content, I followed this SOq, it does not use the virtual env I have on myenv. My file looks like:

#/var/www/html/base/BE/myenv/bin/python    
import sys
sys.path.insert(0, '/var/www/html/base/BE')
    
from be import create_app
application = create_app()

If I add activate_this.py as suggested on this other SOq with the code shared on this GitHub:

activate_this = '/var/www/html/base/BE/myenv/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

I get the error:

mod_wsgi (pid=34272): Failed to exec Python script file '/var/www/html/base/BE/base_be.wsgi'.
mod_wsgi (pid=34272): Exception occurred processing WSGI script '/var/www/html/base/BE/base_be.wsgi'.
Traceback (most recent call last):
  File "/var/www/html/base/BE/base_be.wsgi", line 4, in <module>
    exec(file_.read(), dict(__file__=activate_this))
  File "<string>", line 28, in <module>
AttributeError: 'str' object has no attribute 'decode'

On my_application.conf, I have:

<VirtualHost *:80>
    ServerName api.base
    WSGIDaemonProcess api.base python-path=/var/www/html/base/BE python-home=/var/www/html/base/BE/myenv
    WSGIProcessGroup api.base
    WSGIScriptAlias / /var/www/html/base/BE/base_be.wsgi 
    <Directory /var/www/html/base/BE/>
            Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And I have added api.base to my /etc/hosts

Everytime I try to access the application using: api.base/auth/login, I just get error 500.

  • How can I have my application running and accessible from "api.base/auth/login"?
  • What am I missing here?
  • What type of dark magic is happening?
Javi M
  • 97
  • 9

1 Answers1

0

what flask version are you using? 2.0?

im not sure what you want to achive with

import sys
sys.path.insert(0, '/var/www/html/base/BE')

maybe comment it away

and last

the github that you are using it has a comment (https://github.com/pypa/virtualenv/tree/main/src/virtualenv/activation)

Do not use deprecated API

in the python part

Zerdek
  • 1
  • 2