Flask app running through NSSM - Can't access images

35 views Asked by At

I've created a flask app that gets userinformation from a local DB (that fetches data from AD). When I run this local on my PC or on a server : "python app.py", everything works.

When I create the service that should run this app through NSSM, it doesn't get access to the photos of the users, just the "avatar.jpg" photo that I put on users that doesn't have a photo in AD. The service is set to run on my admin account, that has acces to the folder and files, tried to give direct acces with full permissions to. Also tried to run the service with "Local System", but no luck here either.

It's "cleary" that NSSM is the "issue" and was wondering if anoyone had this issue before or might know a solution?

Part of my python file - app.py

@app.route('/')
def index():
    cursor = mysql.connection.cursor()
    cursor.execute(BLANKED OUT...)
    users = cursor.fetchall()

    updated_users = []
    for user in users:
        image_path = os.path.join('Photos', user[0] + '.jpg')
        image_path = image_path.replace('\\', '/')
        if not os.path.isfile(os.path.join('static', image_path)):
            image_path = 'Photos/avatar.jpg'
        updated_users.append(user + (image_path,))

    return render_template('users.html', users=updated_users)

    return render_template('users.html', users=users)

All the photos is stored under Projectfolder\static\Photos.

  • static
  • Photos
  • templates
  • venv
  • app.py ++

Tried to give direct access to the project folder to my admin account on the server (same as the service run on) with full permissions. Also tried to run the service with "Local System", but no luck here either. When I try to run it locally (without NSSM service) it works.

1

There are 1 answers

1
ViRusi92 On

Solved the issue with a rewrite of how the images is pulled.

Created an app.route for userimages/ and changed the URL in the index. It now works.