1

I'm trying to launch a message box from a python systemd service which is running as root.

subprocess.Popen(["/usr/bin/zenity", "--info", "--text", "please reboot for changes to take effect"], env=dict(os.environ, DISPLAY="0.0", XAUTHORITY="/home/pi/.Xauthority"))

I've set the environment variable DISPLAY and XAUTHORITY however I still get a connection refused message

** (zenity:5491): WARNING **: Could not open X display
Unable to init sever: Could not connect: Connection refused
(zenity:5491): Gtk-WARNING **: cannot open display: 0.0

Is there anything I'm missing here?

4
  • 1
    Could you try DISPLAY = ":0.0"?
    – BoboDarph
    Commented Jun 21, 2017 at 10:43
  • yup, working now - pretty dumb mistake. Cheers Commented Jun 21, 2017 at 11:42
  • Most excellent :D
    – BoboDarph
    Commented Jun 21, 2017 at 12:34
  • @BoboDarph would you post that suggestion as an answer?
    – pneumatics
    Commented Jun 21, 2017 at 21:28

1 Answer 1

3

Most likely due to incorrect value in DISPLAY env var. Try DISPLAY = ":0.0"

subprocess.Popen(["/usr/bin/zenity", "--info", "--text", "please reboot for changes to take effect"], env=dict(os.environ, DISPLAY=":0.0", XAUTHORITY="/home/pi/.Xauthority"))
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.