Python Forum

Full Version: Login to Corporate Website
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm trying to write a script to login to a corporate website to download reports. I already have the code in PowerShell but I would like to write the same in Python instead. Wonder if someone could point me in the right direction.
My main concern is to write a code that is secure - worry about password being stolen during the process.

Quote:$report_Date = "08/13/2018"
$pwd = Get-Content "c:\myfolder\crd.txt" | ConvertTo-SecureString
$crd = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "username",$pwd
$url = "https://randomcorporatewebsite&start=$report_Date&end=$report_Date&outFormat=csv"
$file = "C:\Download\download_rpt.csv"
Invoke-WebRequest -uri $url -Credential $crd -TimeOutSec 600 -UseBasicParsing -OutFile $file

thank you!
Could you elaborate on your main concern? Are you trying to use Python to solve that problem that exists in the PowerShell script? Where is the password stored, if it is at all, and do you have any ideas on where it would be more secure?
Hi,

I already have the code that is working in Powershell. However, I would like to code it Python instead.

If I were to write a Python script to login to a website I imagine it would be like this:

data = {"username":"username",
"password":"password"}
req = requests.post("https://randomcorporatewebsite&start=$report_Date&end=$report_Date&outFormat=csv", params = data)

1) I don't know if the dictionary format of the variable data above would fit the format that the website requires.
When I code it using Powershell the code would be like this:

$crd = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "username",$pwd

I wonder if I should try this instead?
data = "username", "password"

2) the Python code: requests.post
how to code it so that I could direct path or directory to download the csv file?

In Powershell I have: -OutFile $file
in the Invoke-WebRequest method or function

3) lastly, how do I ensure that when I send out the request, my username and password is secure?

Thank you!