I am new to python. I have powershell script which downloads logs for me from web. I want same script in python.
PowerShell script -
$outfile = "/logs.csv"
$connectionToken=""
$base64AuthInfo=[System.Convert]::ToBase64String([System.Text.Encoding]::
ASCII.GetBytes(":$($connectionToken)"))
$AuditLogURL = "https://auditservice.dev.azure.com/{org}/_apis/audit/downloadlog?
format=csv&startTime=2020-07-01T00.00.00&endTime=2020-10-
15T16.00.00&api-version=6.1-preview.1"
$AuditInfo = Invoke-RestMethod -Uri $AuditLogURL -Headers @{authorization = "Basic
$base64AuthInfo"} -Method Get –OutFile $outfile
I have created python script which calls the url but I am not sure how to download file in specified folder from this script -
import requests
import base64
pat = ""
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')
url="https://auditservice.dev.azure.com/{org}/_apis/audit/downloadlog?
format=csv&startTime=2020-07-01T00.00.00&endTime=2020-10-15T16.00.00&api-version=6.1-
preview.1"
headers = {
'Accept': 'application/json',
'Authorization': 'Basic '+authorization
}
response = requests.get(url, headers=headers)