#!/usr/bin/env python3
import socket
import subprocess
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('8.8.8.8', 80))
ip_address = s.getsockname()[0]
s.close()
return ip_address
except Exception:
print("Error getting IP address.")
return None
def launch_fullscreen_chromium():
ip = get_ip_address()
if ip:
command = f"chromium-browser --start-fullscreen --noerrdialogs --hide-crash-restore-bubble --disable-gpu 'http://{ip}/index.php'"
subprocess.call(command, shell=True)
else:
print("Could not retrieve IP address.")
if __name__ == "__main__":
launch_fullscreen_chromium()
当我从终端运行脚本时,它运行正常,但是从crontab -e中,我会从日志中获得以下错误:
[186875:186875:0318/202225.133327:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
[186875:186875:0318/202225.133388:ERROR:env.cc(225)] The platform failed to initialize. Exiting.
我尝试了我能想到的一切。 克朗守护程序正在运行。 我根本无法解决这个问题。
我已经遇到了一个类似的问题,对我而言,这是由于Cron无法访问您的变量而造成的,因此,如果它试图显示某些内容,则未设置$DISPLAY
指定您的外壳中的
$DISPLAY
的值:
对于我来说,它说
$DISPLAY
是:0
,所以我必须在运行cron任务之前导出此变量:
@reboot export DISPLAY=:0 && sleep 60 && /usr/bin/python3 /home/pi/ads.py
如果这不起作用,因为Timroberts
浮出水面,可能是在某些系统上您不能将图形接口作为root使用,因此,如果可能为用户酶添加该任务,则可能需要将任务添加到用户crontab而不是rootOne
sudo crontab -u username -e