Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python XML API request on Linux cmd returns output with request's detail. Is there a way to hide or not receive it?

Here is the example :

query_state = "curl -k --location -g --request GET 'https://hostname/api/?type=op&cmd=<show><state></state></show>&key=API-KEY'"
get_state = os.popen(query_state).read()

soup = BeautifulSoup(get_state, 'lxml')
state = soup.find('state').string
print(state)

Here is output:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4538  100  4538    0     0  27840      0 --:--:-- --:--:-- --:--:-- 27840

active

I need only ‘active’ which is fine, but to reject request view?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried with:

get_state = os.system(query_state)

but output cannot be assigned to a variable.

>Solution :

You can hide the verbose output with the curl --silent flag.

https://curl.se/docs/manpage.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading