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 = "https://api.onelogin.com/api/v3/saml/assertion"
    #get saml assertion
    $request = @{
        api_key='abc'
        username='abc@abc.com' 
        password='abc'
        app_id='123'
    }
    $json = $request | ConvertTo-Json

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

    #login to myapp
    $myappUrl = "https://myapp.com/sso/response"
    $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        
}