I have this curl command that I want into python code command = ' curl -k -u test:123 -H "Content-type: application/json" --digest "https://192.168.0.10/restapi/config/minutes/"'
The command works fine in the terminal
I have tried two methods using pycurl and requests. Apparantely, none of them work. Let me share further on this:
Pycurl approach:
import pycurl
from io import StringIO
buffer = StringIO()
url = "https://192.168.0.10/restapi/config/minutes/"
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.SSL_VERIFYPEER, False)
curl.setopt(pycurl.USERPWD, 'test:123')
curl.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
curl.setopt(pycurl.VERBOSE, 1)
curl.perform()
resp = buffer.getvalue()
I get empty string as an output
Requests approach:
import requests
headers = {
'Content-Type': 'application/json',
}
response = requests.get(url, headers=headers, verify=False, auth=('test', '123'))
I get "Response [401]"
where am I going wrong? I know that subprocess is not a recomended option, but it is the only method that seems to work :
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()