Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login to Corporate Website
#1
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!
Reply
#2
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?
Reply
#3
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,265 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  Problem to use pip behind cntlm / corporate proxy markus7811 3 22,201 May-02-2018, 02:21 PM
Last Post: ljmetzger
  Login a Python Web Crawler on a ASP NET (.aspx) website p4t3x 1 7,011 Dec-01-2017, 11:09 AM
Last Post: hshivaraj

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020