Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2123992
  • 博文数量: 229
  • 博客积分: 7217
  • 博客等级: 上校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 17:23
个人简介

个人主页https://xugaoxiang.com,微信公众号: Dev_Club 或者搜索 程序员Club

文章分类

全部博文(229)

文章存档

2017年(1)

2016年(20)

2015年(23)

2013年(1)

2012年(23)

2011年(68)

2010年(62)

2009年(31)

分类: LINUX

2010-05-31 14:27:09

In some situation,you may need CGI server show some message or icons when receiving a request from the client.Take OSD notification as an example,when the client sending an access request,CGI server will display useful information right now.

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

import cgi
import os

print 'Content-Type:text/html\n\n'
os.system("notify-send 'hello' 2>/tmp/notify-error")


But it do not work.And notify-send 'hello' works well in gnome-terminal.I check the log file /tmp/notify-error

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


That means notify-send cannot connect current X session.So I add the DISPLAY variable as the following.

os.system("DISPLAY=:0.0 notify-send 'hello' 2>/tmp/notify-error")


But the error remains.

Suddenly I remebered some days ago I use the python module pynotify to realize the OSD notification.Why not have a try?I download python-notify from

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

import cgi
import os

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

try:
    import pynotify
    if pynotify.init("cgi script"):
        n = pynotify.Notification("Title", "message")
        n.show()
    else:
        print "There was a problem initializing the pynotify module"
except:
    print "Have not pynotify installed"


I check the apache2 error.log,error as same as before in great disappointment.
An idea flashs in my mind,the apache2 default user www-data and my system username djstava is not the same one.Maybe this is the problem.Then I change the apache2's default user www-data to my system user djstava,and it works,ONLY need the $DISPLAY.




djstava
阅读(2177) | 评论(0) | 转发(0) |
0

上一篇:Irxevent on startup

下一篇:Osdlyrics

给主人留下些什么吧!~~