1

To download a file from a web server, I do below -

import wget

url = "https:xxxxx/file"

iso_filename = wget.download(url, '/Users/xxxxx/Downloads/')

Now, I am trying to download a file from a website which requires authentication.

User credentials involve special characters - @, # etc

I would like to know a way of how to supply username and password in python3 while using wget ?

I would prefer to use wget unless there isn't any other option to overcome this issue.

Any advise would be highly appreciated.

PSD
  • 11
  • 7
  • Does this answer your question? [Wget & Python / No user option](https://stackoverflow.com/questions/37386644/wget-python-no-user-option) – MisterMiyagi Sep 14 '21 at 10:22
  • No, it works with simple username password, but doesn't works with credentials like - uid - abc@xxx.com psw - xyz@ – PSD Sep 14 '21 at 10:27
  • Does this answer your question? [URL: Username with @](https://stackoverflow.com/questions/10050877/url-username-with) – MisterMiyagi Sep 14 '21 at 10:28
  • No, unfortunately it didn't helped - uid = user.name@website.com psw = password@1234 Below is the sample code which returns an exception - filename = wget.download('https://user.name%40website.com : password%401234@website.com/bin/support/download?sid=u0ijav0to9j6u', '/Users/localmachine/Downloads/') – PSD Sep 14 '21 at 15:08
  • If you are using basic auth you can use `https://:@host.com/path` – M. Liver Sep 14 '21 at 15:48
  • I am not sure if we can use this with wget.download() as it says the syntax isn't valid for the url – PSD Sep 14 '21 at 16:50

1 Answers1

0

I finally gave up on using wget.download(), what worked for me is scp, explained as below -

sshpass -f 'path to psw file' scp -r user@10.X.X.X:/file_path /path_to dowload_file

ex:

sshpass -f 'usr/bin/psw.txt' scp -r user@10.X.X.X:/usr/bin/ubuntu.iso /remote/user/iso

psw.txt to pass password in a file to avoid been listed in bash history etc...

PSD
  • 11
  • 7