[英]download password protected file from owncloud with python
如何在python
中下載受密碼保護的文件?
該文件通過Owncloud
共享,訪問受Owncloud
密碼保護。
我知道它可以通過以下方式與curl
一起使用:
curl -u "FileId:FilePw" -H 'X-Requested-With: XMLHttpRequest' "https://exampledomain.com/public.php/webdav/" >output_file
字段文件 id FileId
是從共享鏈接中提取的。
有些網頁可以將curl
命令轉換為許多不同的語言和模塊 - 甚至是Python
和requests
- 即。 卷發器
import requests
headers = {
'X-Requested-With': 'XMLHttpRequest',
}
response = requests.get('https://exampledomain.com/public.php/webdav/',
headers=headers,
auth=('FileId', 'FilePw'))
這只需要以二進制模式保存響應
with open('filename.ext', 'wb') as fh:
fh.write( response.content )
您可以使用 os 模塊將命令嵌套到系統調用中
system_object = os.system('your command')
或 fork 一個新進程並使用子進程運行
myProcess = subprocess.run()
requests 模塊允許您使用 http 命令
import requests
headers = {}
response = requests.method(params)
重要的部分是您將對象變量分配給實例方法,以便您可以使用文件對象
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.