Jun-25-2018, 04:51 PM
The following are what I have in powershell
# Get a SIM Session Cookie
Invoke-WebRequest -UseDefaultCredentials -UseBasicParsing -Uri https://maxis-service.domain.com/users/whoami -SessionVariable sim
#Send Post to Create Job
$response = Invoke-RestMethod -UseDefaultCredentials -UseBasicParsing -WebSession $sim -Uri https://maxis-service.domain.com/jobs -Method Post -Body $json -ContentType "application/json"
I believe this should translate to a session with requests, but if I am wrong please let me know.
I tried using the following in Python after a lot of google, but it doesn't seem to work like I thought it did (similar to what powershell is doing):
# Get a SIM Session Cookie
Invoke-WebRequest -UseDefaultCredentials -UseBasicParsing -Uri https://maxis-service.domain.com/users/whoami -SessionVariable sim
#Send Post to Create Job
$response = Invoke-RestMethod -UseDefaultCredentials -UseBasicParsing -WebSession $sim -Uri https://maxis-service.domain.com/jobs -Method Post -Body $json -ContentType "application/json"
I believe this should translate to a session with requests, but if I am wrong please let me know.
I tried using the following in Python after a lot of google, but it doesn't seem to work like I thought it did (similar to what powershell is doing):
sessionURL = 'https://maxis-service.domain.com/users/whoami'
simURL = 'https://maxis-service.domain.com/jobs'
s = requests.Session()
sr = s.get(sessionURL,verify=False)
cookie = s.cookies
print(cookie)
dr = s.post(simURL,data=rawJson,verify=False)cookie prints the expected cookie, but then the post request gives a 401; is there a reason that python gets a 401? am I not using the session correctly?
