'Python-daemon, daemonContext has Errno 13 permission errors for file editing, running with a umask as root

https://paste.pythondiscord.com/cidubevunu.py This is my code I am using running python-daemon.

I am following this guide which seems to be going great, until I run daemonContext and I don't have permission apparently to edit files and other things. I think it may have something to do with the umask. I am new to some of these concepts but I have read up on them. I need anything educated feedback for any at all if this situation below:

(venv) user123@PC shoutout % 511
6969 666
/
Traceback (most recent call last):
  File "/Users/user123/PycharmProjects/shoutout/shoutout_daemon.py", line 27, in <module>
    class Daemon():
  File "/Users/user123/PycharmProjects/shoutout/shoutout_daemon.py", line 68, in Daemon
    with open("/Users/user123/Desktop/cool.txt", "w") as f:
PermissionError: [Errno 13] Permission denied: '/Users/user123/Desktop/cool.txt'

As I can't have permissions to edit any file, despite it's owner ship to me or it's perms changing to per se 777 etc. I run this with sudo (root) to avoid this error: In case your user doesn’t have root permissions, DaemonContext will raise a DaemonOSEnvironmentError exception.

But the errno 13 pops-up. Is this a problem clearly with the umask likely? I have changed the umasks octal number/code to various permissions for read/write/execution like this:

    umask=0o777, # it has been 0o002 as well (stackoverflow note here)
    uid=6969,
    gid=666,
    pidfile=lockfile.FileLock('/var/run/shoutout.pid'),
    signal_map={
        signal.SIGTERM: shutoff,
        signal.SIGTSTP: shutoff
    }):
umask = os.umask(0o777) # in the article it sets this to 0 originally, reverse that?
os.umask(umask)

Hopefully I can run my daemon soon without any permission stuff. If anyone could help to resolve why this is occurring please pitch in :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source