How to deal with interactive API in python
Asked Answered
S

1

6

I'm in a situation where I need to pass some texts to a prompt generate by a API (seems for API it's a pretty weird behavior, this is the first time I ran into this), like below:

kvm_cli = libvirt.open("qemu+ssh://[email protected]/system")

then a prompt shows up asking for the ssh password (password for 10.0.10.8 is:), I have to manually type it there in order to move on and yield the kvm_cli object I needed.

I tried to use the pexpect module to deal with this however it's for OS command line instead of API.

It's also possible to work around this by using ssh certification files but it's not a favorable authentication approach in our scenario.

Since our wrapper to the 'open' method is not interactive, we cannot ask the user to input the password, do you guys have any thought how could I address it?

Stereotropism answered 10/2, 2011 at 8:17 Comment(1)
I guess ssh certification files are the same as the 'key-based' login Andrea has suggested. why do you think ssh certificates not a viable approach to this problem, it is what I would use in the situation.Pressmark
P
4

I am not a libvirt user, but I believe that the problem is not in the library, but in the connection method. You seem to be connecting via ssh, so you need to authenticate yourself.

I've been reading the libvirt page on ArchWiki, and I think that you could try:

Parclose answered 10/2, 2011 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.