-
Notifications
You must be signed in to change notification settings - Fork 38
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
ConnectionError: could not open interface on Ubuntu #133
Comments
Hi, sorry I'm also no expert on Linux and don't know how to get around this. Maybe someone with enough knowledge reads this and can provide help. |
Just wanted to follow up on this. After digging into this for a couple of days, and working with some embedded engineers, here is a single (1) solution to this problem. There may be others, but this is the most streamlined. I will be spending time figuring out how to make this work best in a docker container, but for the time being you can use this method for both your home (base) python environment or virtual ones. It should also work with C++ and other languages as well, just with some modification of what your "executable" is. Assuming we are using python:
You will get a response that looks something like this: Now that you know you are using python 3.8 (or whatever one you are using), then run:
You will get a reply that looks like: Now, you know that when you call python in command line,
Where the final argument is the location of your python executable (as determined in step 2). Hopefully this helps out anyone trying to work with opening ports/adapters for ethernet/ethercat on linux/ubuntu systems. |
def request_root_permissions(m_path, m_pid):
args = ["pkexec", "python3", m_path, str(m_pid)]
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait(60)
if process.returncode == 1:
return True
else:
return False
su_state = True
if os.getuid() != 0:
app_path = os.path.abspath(sys.argv[0])
pid = os.getpid()
su_state = request_root_permissions(app_path, pid)
# Do what you want..... |
The request root permissions asks for permission but still does not work. Still got I had to create and venv to install the lib and start the python script as root: Create venv python -m venv .venv Activate it: source .venv/bin/activate Install pip packages: pip install -r requirements.txt Run python with sudo while using the full .venv path for python sudo /.venv/bin/python script.py |
I am curious as to if it is at all possible to open a connection to an adapter on Ubuntu without having to run things as root. For instance, I would like to just run
master.open(<portname>)
without having to first run the python script assudo python name_of_script.py
.Is there any way to open this adapter up so that we don't need to be the super user to access it? It is pretty straight forward-ish to do this in windows, but I cannot be installing all of my pip packages as sudo on my system (doing so would complicate everything within dockers and such). Hoping there is an easy way to sidestep this issue without jumping through too many hoops.
Current code:
Error message:
The text was updated successfully, but these errors were encountered: