Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] uWSGI: Fix permission denied on subprocess.getoutput #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MatteoNet
Copy link

Using uWSGI on Linux, Python fails to call subprocess.getoutput method due to a permissions problem.

mkdir: cannot create directory '/.local': Permission denied
touch: cannot touch '/.local/share/applications/mimeapps.list': No such file or directory

Using the subprocess.check_output method, no directory creation request is made and the command returns the expected value

To be tested on other OS

version = subprocess.getoutput(f"{executable_path} --version 2>&1").strip()
version = subprocess.check_output([executable_path, "--version"]).decode().strip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have to test this later because --version can sometimes include error messages on some platforms/browsers, hence the 2>&1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I have added the 2>&1 argument back in.

@roniemartinez
Copy link
Owner

@MatteoNet

Do you have an error log which lines was causing the issue? I tried checking out your changes but it fails on Ubuntu, snap-installed browsers.

mkdir: cannot create directory '/.local': Permission denied
touch: cannot touch '/.local/share/applications/mimeapps.list': No such file or directory

Looking at the code, I believe it is not related to getoutput() as this line is only running {browser} --version command and not mkdir.

@roniemartinez
Copy link
Owner

@@ -44,7 +44,7 @@ def browsers() -> Iterator[Browser]: # type: ignore[return]
executable_path = entry.getExec()
if executable_path.lower().endswith(" %u"):
executable_path = executable_path[:-3].strip()
version = subprocess.getoutput(f"{executable_path} --version 2>&1").strip()
version = subprocess.check_output([executable_path, "--version", "2>&1"]).decode().strip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = subprocess.check_output([executable_path, "--version", "2>&1"]).decode().strip()
version = subprocess.getoutput(f"{executable_path} --no-sandbox --version 2>&1").strip()

Can you instead try this? --no-sandbox looks fine on Firefox, too but I certainly did not test it on other browsers.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also advise to run several command line switches like --disable-default-apps. Not sure which one will solve this issue but you can check https://peter.sh/experiments/chromium-command-line-switches/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants