How to use saml data to login

We are trying to port the oneLogin saml logic to Python, i am able to successfully get the $saml result from the 1st part. However, getting 500 error code for the part that logs in to my app. Could someone point to to the right path to rewrite the login to app part by using Python requests package from powershell? Thanks.

function session () {
    $oneloginUrl = ""
    #get saml assertion
    $request = @{
    $json = $request | ConvertTo-Json

    $response = Invoke-RestMethod $oneloginUrl -Method Post -Body $json -ContentType 'application/json'
    $saml = $

    #login to myapp
    $myappUrl = ""
    $form = New-Object Microsoft.PowerShell.Commands.FormObject -ArgumentList "test","post","submit"
    $form.Fields.add("RelayState","/" )
    $form.Fields.add("SAMLResponse", $saml)
    $r=Invoke-WebRequest $myappUrl -SessionVariable myapp -Body $form.fields -Method post
    return $myapp