Python:pynotify网络问题
我正在使用 pynotify 这是我试图开始工作的代码:
#! /usr/bin/python
try:
import pynotify
if pynotify.init("Telebrama Alert"):
n = pynotify.Notification('Message','This is test message')
n.set_urgency(pynotify.URGENCY_CRITICAL)
n.show()
else:
print 'There was a problem in initializing the pynotify module'
except:
print "you don't seem to installed pynotify\n"
它工作正常在我的电脑上。但我想向另一个网络发送一些通知。我怎样才能让它发挥作用?
I am using pynotify and this is the code I am trying to get to work:
#! /usr/bin/python
try:
import pynotify
if pynotify.init("Telebrama Alert"):
n = pynotify.Notification('Message','This is test message')
n.set_urgency(pynotify.URGENCY_CRITICAL)
n.show()
else:
print 'There was a problem in initializing the pynotify module'
except:
print "you don't seem to installed pynotify\n"
It is working fine on my computer. But I want to send some notification to another network. How can I make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
pynotify
只是一个 X 客户端。要连接非本地 X 服务器,您必须设置 DISPLAY 环境变量。请注意,您要连接的 X 服务器应配置为接受远程连接(请参阅 xhost 和 xauth 的手册页)。pynotify
is just an X client. To connect non-local X server you have to set DISPLAY environment variable. Note, that X server you are going to connect to should be configured to accept remote connections (see man pages for xhost and xauth).好吧,你应该明白 pynotify 与网络无关。
pynotify 是 libnotify 的 Python 绑定。 libnotify 是关于桌面(本地)通知的。它使用本地 D-Bus 消息总线。没有网络。因此,如果您想将通知发送到另一个桌面,则必须使用其他工具。
Well you should understand pynotify is not about network.
pynotify is the Python binding for libnotify. libnotify is about desktop (local) notification. It uses the local D-Bus message bus. No network. So if you want to send a notification to another desktop you will have to use some other tool.
根据您的 DISPLAY 变量,您可以通过以下方式使其工作:
import os
os.environ['DISPLAY'] = ':0.0'
Depending on your DISPLAY variable, you can get this to work by:
import os
os.environ['DISPLAY'] = ':0.0'