LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   notify-send not work as CGI script? (https://www.linuxquestions.org/questions/linux-desktop-74/notify-send-not-work-as-cgi-script-811177/)

djstava 05-30-2010 09:30 PM

notify-send not work as CGI script?
 
I write a cgi script in python just send a notification command,but that can not work for me.

Code:

#!/usr/bin/env python
#-*-coding=utf-8-*-

import cgi
import os

print 'Content-Type:text/html\n\n'

os.system("notify-send 'hello'")


And
Code:

djstava@Gateway:~/test$ notify-send 'hello'
is OK.

This is the error.
Code:

djstava@Gateway:/tmp$ cat notify-error
libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.


** (notify-send:4642): CRITICAL **: dbus_g_proxy_connect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed

** (notify-send:4642): CRITICAL **: dbus_g_proxy_connect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed

** (notify-send:4642): CRITICAL **: dbus_g_proxy_call: assertion `DBUS_IS_G_PROXY (proxy)' failed
libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.


** (notify-send:4642): CRITICAL **: dbus_g_proxy_disconnect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed

** (notify-send:4642): CRITICAL **: dbus_g_proxy_disconnect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed

(notify-send:4642): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed


MS3FGX 05-30-2010 10:55 PM

I can't actually see what is in your CODE tags because I am on my phone, but the problem is almost certainly the fact that the script is not being executed as the user with the X session, but rather the user your web server is setup to run under.

The problem is, you certainly don't want the web server running under your normal user account either.

djstava 05-30-2010 11:10 PM

Quote:

Originally Posted by MS3FGX (Post 3986944)
I can't actually see what is in your CODE tags because I am on my phone, but the problem is almost certainly the fact that the script is not being executed as the user with the X session, but rather the user your web server is setup to run under.

The problem is, you certainly don't want the web server running under your normal user account either.

Yes,I change the apache2's default user www-data to my system user djstava,and it works,ONLY need the $DISPLAY.Just like this,
Code:

os.system("DISPLAY=:0.0; notify-send 'hello'")
Thank you.


All times are GMT -5. The time now is 01:16 PM.