Python应用程序.desktop-shortcut导致故障 [英] Python-Application .desktop-shortcut causing malfunction

查看:188
本文介绍了Python应用程序.desktop-shortcut导致故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的Python应用程序创建一个桌面启动器.应用程序使用公钥身份验证在pexpect上执行各种ssh操作.但是问题是,当我使用.desktop启动器启动应用程序时,它无法正常运行. ssh连接要求输入密码,并且不使用公共密钥.但是它可以通过命令行执行正常工作.

I wanted to create a desktop launcher for my Python application. The application executes various ssh operations over pexpect with publickey-authentication. The problem is however, when I start my app with the .desktop launcher it doesn't work properly. The ssh connections ask for a password and don't use the publickeys. But it works fine via commandline execution.

.desktop文件如下所示:

The .desktop File looks like this:

[Desktop Entry]
Version=1.0
Name=SSH-Manager
Comment=XYZ
Exec=python /home/userx/SSH-Manager/startup.py
Icon=/home/userx/SSH-Manager/resources/icon.png
Path=/home/userx/repos/SSH-Manager
Terminal=true
Type=Application
Categories=Utility;Application;
StartupNotify=false

桌面环境为KDE,桌面用户与命令行用户相同.

The desktop environment is KDE and the desktop user is the same as the commandline user.

有人可以解释为什么我在启动器中出现这种奇怪的行为吗?

Can someone explain why I get such strange behavior with the launcher?

示例函数

def run(self):
    self.a_signal.emit("Retrieving Data")
    try:
        session = pxssh()
        session.force_password = False
        hostname = self.client
        username = "root"
        session.login(hostname, username)
        session.sendline("ls -a")
        session.prompt()
        session.logout()
    except ExceptionPxssh as e:
        print ("pxssh failed: ")
        self.error_signal.emit("failed", str(e))
        print e
        return
    self.process_output()
    self.finish_signal.emit("done")

推荐答案

正如MirosławZalewski在评论中所怀疑的那样,问题在于ssh-agent不在桌面环境中运行,因为ssh-add最初是在/etc/sources.因此,在X用户~./profile中执行ssh-add可以解决该问题.

As Mirosław Zalewski suspected in the comments, the problem was the ssh-agent was not running for the desktop-environment because ssh-add was initially used in the /etc/sources. Executing ssh-add in the X-users ~./profile therefore solves the problem.

这篇关于Python应用程序.desktop-shortcut导致故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆