How can I download a password protected file inside python
?
The file is shared via Owncloud
and the access is protected with a password by Owncloud
.
I know it works with curl
by using:
curl -u "FileId:FilePw" -H 'X-Requested-With: XMLHttpRequest' "https://exampledomain.com/public.php/webdav/" >output_file
The field file id FileId
is extracted from the shared link.
There are web pages which can convert curl
command to many different languages and modules - even to Python
and requests
- ie. Curl Converter
import requests
headers = {
'X-Requested-With': 'XMLHttpRequest',
}
response = requests.get('https://exampledomain.com/public.php/webdav/',
headers=headers,
auth=('FileId', 'FilePw'))
And this needs only to save response in binary mode
with open('filename.ext', 'wb') as fh:
fh.write( response.content )