playwright doesn't respond with systemctl service

Question:

My server is running on Ubuntu 22.04.1 LTS and I have a python flask app which runs perfectly with an active virtual environment (source bin/activate) using wsgi [python 3.10]. While all my other routes are working fine, I can’t make playwright related routes run using systemctl service. For some reason it doesn’t react to my code and throws no Error. Any idea what am I doing wrong here?

#function that runs inside playwright route
    try:
        from playwright.sync_api import sync_playwright
        import sys
        print('n'.join(sys.path))

        with sync_playwright() as p:
            url = "https://www.wikipedia.org/"
            browser = p.chromium.launch(headless=True)
            Logger(f"opening {url} ...").info()
            context = browser.new_context()

            # Open new page
            page = context.new_page()
            page.goto(url)
            Logger(page.title(), 'is the title').log()

    except BaseException as error:
        print('An exception occurred: {}'.format(error))

here is the console log of the function above:
console log

my systemctl config:

[Unit]
Description=uWSGI instance to serve foo
After=network.target

[Service]
User=boo
Group=www-data
WorkingDirectory=/home/boo/foo
Environment="PATH=/home/boo/foo/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/home/boo/foo/bin/uwsgi --ini app.ini

[Install]
WantedBy=multi-user.target

app.ini:

[uwsgi]
module = wsgi:app

master = true
processes = 5

pythonpath = /home/foo/boo/lib/python3.10/site-packages

socket = api-server.sock
chmod-socket = 660
vacuum = true

die-on-term = true

installed packages list:

attrs==22.1.0
certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.3
cssselect==1.2.0
exceptiongroup==1.0.4
Flask==2.2.2
greenlet==2.0.1
idna==3.4
iniconfig==1.1.1
itsdangerous==2.1.2
Jinja2==3.1.2
lxml==4.9.1
MarkupSafe==2.1.1
packaging==22.0
parsel==1.7.0
playwright==1.28.0
pluggy==1.0.0
pyee==9.0.4
pytest==7.2.0
requests==2.28.1
tomli==2.0.1
typing_extensions==4.4.0
urllib3==1.26.13
uWSGI==2.0.21
w3lib==2.1.1
Werkzeug==2.2.2

Answers:

For future visitors, the playwright needs access to your /usr/bin and my initial approach of adding different bin directories was wrong. I should have used the following code to extend the PATH:
Environment="PATH=$PATH:/usr/bin"

my server is working fine now.

Answered By: Farrokh Rostami Kia