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

Permission denied when opening /sys/class/gpio/export #25

Open
S4mw1s3 opened this issue Mar 9, 2022 · 1 comment
Open

Permission denied when opening /sys/class/gpio/export #25

S4mw1s3 opened this issue Mar 9, 2022 · 1 comment
Labels

Comments

@S4mw1s3
Copy link

S4mw1s3 commented Mar 9, 2022

Hi,

I'm running Linux 5.15.16 and I get a Permission denied: '/sys/class/gpio/export' error when instantiating GPIOPin.
I think the FMODE should not be w+ but simply w:

root@sam:~# stat /sys/class/gpio/export
  File: /sys/class/gpio/export
  Size: 4096            Blocks: 0          IO Block: 4096   regular file
Device: 11h/17d Inode: 2618        Links: 1
Access: (0200/--w-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-18 11:35:45.430000000 +0000
Modify: 2022-01-18 11:35:45.430000000 +0000
Change: 2022-01-18 11:35:45.430000000 +0000
root@sam:~#
root@sam:~#
root@sam:~# python3
Python 3.10.2 (main, Jan 13 2022, 19:06:22) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gpio
>>> gpio.GPIOPin(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/gpio/__init__.py", line 49, in __init__
    with open(GPIO_EXPORT, FMODE) as f:
PermissionError: [Errno 13] Permission denied: '/sys/class/gpio/export'
>>>
>>>
>>>
>>>
>>> print(gpio.FMODE)
w+
>>>
>>>
>>> print(gpio.GPIO_EXPORT)
/sys/class/gpio/export
>>>
>>>
>>>
>>>
>>> with open(gpio.GPIO_EXPORT, "w+") as f:
...   print("OK")
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: '/sys/class/gpio/export'
>>>
>>>
>>>
>>> with open(gpio.GPIO_EXPORT, "w") as f:
...   print("OK")
...
OK
>>>
@nazzak
Copy link

nazzak commented Apr 26, 2022

Yes, absolutely, export/unexport are not normal file. We should use "w"

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

No branches or pull requests

3 participants