微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在登录 RPI4 之前使用 systemd 运行 python 脚本以启动脚本时出现无效的 MIT-MAGIC-COOKIE-1 错误

如何解决在登录 RPI4 之前使用 systemd 运行 python 脚本以启动脚本时出现无效的 MIT-MAGIC-COOKIE-1 错误

我正在寻求以下方面的帮助。我想要一个包含 Pygame gui 的 python 脚本,无需登录即可在启动时运行。我正在运行带有 RPI 触摸屏的 RaspBerry Pi 4。

当我在 raspi-config 中启用自动登录时,脚本工作正常。

我使用的 systemd 配置文件 (/etc/systemd/system/SecurityPanel.service):

[Unit]
Description=SecurityPanel
After=multi-user.target

[Service]
Environment=disPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
ExecStart=/usr/bin/python3 /home/pi/SecurityPanel/main.py
Restart=always
RestartSec=10s
KillMode=process
TimeoutSec=infinity
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=SecurityPanel
User=root
Group=root

[Install]
WantedBy=multi-user.target

设置用户是我最近的尝试,但没有成功。我也尝试过使用graphical.target,也没有成功。

我得到的错误(journalctl):

Jan 06 19:35:56 raspBerrypi systemd[1]: Started SecurityPanel.
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]: Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]: Invalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]: Traceback (most recent call last):
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:   File "/home/pi/SecurityPanel/main.py",line 116,in <module>
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:     ui = UI()
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:   File "/home/pi/SecurityPanel/SecurityPanel/ui.py",line 59,in __init__
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:     pygame.init()
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:   File "/home/pi/SecurityPanel/main.py",line 86,in sig_end_SC
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:     end_SC()
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:   File "/home/pi/SecurityPanel/main.py",line 78,in end_SC
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]:     ts.stop()
Jan 06 19:35:57 raspBerrypi SecurityPanel[605]: NameError: name 'ts' is not defined
Jan 06 19:35:58 raspBerrypi SecurityPanel[605]: pygame 1.9.4.post1
Jan 06 19:35:58 raspBerrypi SecurityPanel[605]: Hello from the pygame community. https://www.pygame.org/contribute.html
Jan 06 19:35:58 raspBerrypi SecurityPanel[605]: starting output to /home/pi/SecurityPanel/logs/SC9.log
Jan 06 19:35:58 raspBerrypi systemd[1]: SecurityPanel.service: Main process exited,code=exited,status=1/FAILURE
Jan 06 19:35:58 raspBerrypi systemd[1]: SecurityPanel.service: Failed with result 'exit-code'.
Jan 06 19:36:08 raspBerrypi systemd[1]: SecurityPanel.service: Service RestartSec=10s expired,scheduling restart.
Jan 06 19:36:08 raspBerrypi systemd[1]: SecurityPanel.service: Scheduled restart job,restart counter is at 1.
Jan 06 19:36:08 raspBerrypi systemd[1]: Stopped SecurityPanel.

输出谁:

pi       pts/0        Jan  6 20:03 (<MY_IP>)

输出回显 $disPLAY

<nothing>

主机+本地:

not found: 3(NXDOMAIN)

我认为后者是问题,但不知道如何解决它...

任何帮助将不胜感激! 谢谢,J

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。