Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with interactive API in python

Tags:

python

libvirt

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?

like image 766
Ripley Avatar asked Feb 10 '11 08:02

Ripley


People also ask

How does Python interact with API?

To interact with an API, specifically a web API in python we can make use of the standard requests module to make the request, because most web service APIs return a response in a format known as JSON it will be useful to know little about it. JSON is a way to store data in an organized, logical manner.

Can I use Python with Interactive Brokers?

Supported languages currently include Python, Java, C++, and . NET. There is also support for Microsoft's ActiveX framework as well as DDE to establish a connection within Excel. What makes IB unique is that a connection is made to the IB client software which acts as an intermediary to the IB servers.

Can you access API with Python?

By the end of this tutorial, you'll be able to use Python to consume most APIs you come across. If you're a developer, knowing how to consume APIs with Python will make you much more proficient, especially when it comes to integrating your work with third-party applications.


1 Answers

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:

  • setting up the simple (TCP/IP socket) connection method, or
  • setting up key-based, password-less SSH login for your virtual host.
like image 155
Andrea Spadaccini Avatar answered Sep 18 '22 12:09

Andrea Spadaccini