Some background details:
We have an internal site which has SSO with 2FA, and also requires client certs. It has a form which submits a job. I'm trying to automate the process by running it from CLI. So far I have been able to get a job submitted using curl. For it to work I need to extract the cookies from my browser session. So the following curl command is running as expected
curl -b cookies.txt -k --cert cert --key key -F 'field=value' url
I now tried to convert the same to a Python requests call. However it looks like it is not getting the cookies. I can see that from the output of script going to the SSO login page. Here is the script I have so far
from requests_toolbelt import MultipartEncoder
import requests
import http.cookiejar
cookies = http.cookiejar.MozillaCookieJar('cookies.txt')
cookies.load(ignore_expires=True)
cert = ('cert','key')
m = MultipartEncoder(
fields={'field': 'value'}
)
headers = {
'Content-Type': m.content_type,
}
r = requests.request('POST', url, data=m,
headers=headers, cookies=cookies, cert=cert, verify=False)
From what I can i have matched all curl options. But as mentioned it seems to be ignoring the cookies, and tries to run a SSO. Any idea how to get this running? If nothing else works, I would have to run the curl via a subprocess. But i would rather get it going within the Python requests.
Any help/hints much appreciated.