Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Powershell Session translation to Python; Session code seems to not work
#1
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?
Quote
#2
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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  recording a translation table into a file arbiel 0 57 Mar-31-2020, 02:33 PM
Last Post: arbiel
  Code used to work, not anymore for no apparent reason? chicagoxjl 1 135 Jan-08-2020, 05:05 PM
Last Post: jefsummers
  How to clean session mqtt SayHiii 0 175 Dec-09-2019, 07:56 AM
Last Post: SayHiii
  upload image with generated code from Postman does not work magic7598 0 183 Nov-30-2019, 10:32 AM
Last Post: magic7598
  How does this RLE code work? sik 1 189 Nov-21-2019, 03:35 PM
Last Post: ThomasL
  Def code does not work for negative integers. doug2019 1 169 Oct-31-2019, 11:00 PM
Last Post: ichabod801
  Manipulation a file for translation apsyrtos 1 247 Sep-10-2019, 02:56 AM
Last Post: luoheng
  Why does my code only work once? NonSufficitOrbis 0 225 Sep-01-2019, 10:43 AM
Last Post: NonSufficitOrbis
  Code in Periscope does not work switchgirl 1 339 Aug-05-2019, 11:29 AM
Last Post: buran
  Cant get grade part of code to work correctly Expel 5 429 Jul-10-2019, 05:09 AM
Last Post: perfringo

Forum Jump:


Users browsing this thread: 1 Guest(s)