I have a python script which uses motion sensor and camera. It captures an image and stores to the same folder where the script resides. No errors when I run it in bash. But I created this service for systemd to make it run on start up:
[Unit]
Description=Run office intrusion detection
After=network.Target
[Service]
ExecStart=/usr/bin/python3 -u /home/myuser/Documents/prog/pricam.py
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=pricam
User=pi
[Install]
WantedBy=multi-user.target
and when it runs I see this error:
>>Traceback (most recent call last):
File "/home/alvipeo/Documents/progs/pricam.py", line 24, in <module>
camera.capture(filename)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1418, in capture
encoder.start(output)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1126, in start
super(PiCookedOneImageEncoder, self).start(output)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 375, in start
self._open_output(output)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 331, in _open_outpu
t self.outputs[key] = mo.open_stream(output)
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 344, in open_stream
stream = io.open(stream, 'wb' if output else 'rb', buffering)
PermissionError: [Errno 13] Permission denied: '/home/myuser/Documents/progs/pi
cam-2018年06月06日_11.46.38.jpg'
I'm not a good linux user, so could you please tell me what's wrong here?
1 Answer 1
It appears in your system daemon configuration you have "User=pi" while the path to the image is clearly located in the "myuser" user directories. So, likely the permissions are such that user "pi" can not alter user "myuser"'s files.
-
I tries myuser, but that presents another problem with GPIO and camera permissions. so how can I grant pi permission to write files to myuser folders?Alex Bee– Alex Bee2018年06月06日 16:08:01 +00:00Commented Jun 6, 2018 at 16:08
-
If security is not a concern, you can open up the permissions of the directory /home/myuser/Documents/progs (chmod 777 /home/myuser/Documents/progs) so that any user could write to it. However, I would think the easier option is to store the images in a directory owned by user "pi" instead of user "myuser".st2000– st20002018年06月07日 03:37:09 +00:00Commented Jun 7, 2018 at 3:37