Powershell Session translation to Python; Session code seems to not work - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Powershell Session translation to Python; Session code seems to not work (/thread-11153.html) |
Powershell Session translation to Python; Session code seems to not work - Maverick494 - Jun-25-2018 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): 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? RE: Powershell Session translation to Python; Session code seems to not work - Maverick494 - Jun-26-2018 I should probably have expanded here is the output when I print dr as well: <RequestsCookieJar[<Cookie cookie_cookie=1b41fd0a9722b852 for maxis-service.domain.com/>]> <Response [401]> So I can't understand why the post call using the session is giving a 401 |