通过没有用户名和密码对话框的 sftp Pygtk 挂载文件?

Pygtk mount file through sftp without username and password dialog?

我正在尝试通过 pygtk 中的 sftp 挂载目录。因为我已经将用户名和密码存储在变量中,所以我不希望出现一个询问用户名和密码的对话框。我正在使用以下代码:

def error_printer(o,r)
    try:
        o.mount_enclosing_volume_finish(r)
    except gio.Error, e:
        print str(e.message),"error code:", e.code

myfile = gio.File("sftp://" + my_ip_address)
op = gtk.MountOperation()
op.set_username(my_username)
op.set_password(my_password)
my_file.mount_enclosing_volume(op, error_printer)

当我运行这样做时,即使我已经设置了用户名和密码,也会出现一个对话框询问用户名和密码。

我该怎么做才能让对话框不再出现,而是使用我设置的用户名和密码?

(我使用的是 pygtk 2.16)

解决了!
必须像 these guys:

那样做
class DupMountOperation(gio.MountOperation):
"""A simple MountOperation that grabs the password from the environment
   or the user.
"""
def __init__(self, backend):
    gio.MountOperation.__init__(self)
    self.backend = backend
    self.connect('ask-password', self.ask_password)

def ask_password(self, *args, **kwargs):
    self.set_password(self.backend.get_password())
    self.reply(gio.MOUNT_OPERATION_HANDLED)