Last active
March 28, 2021 14:50
-
-
Save tsuemura/0d26aff99990fd483430c3639fee48a1 to your computer and use it in GitHub Desktop.
PythonでBasic認証付きのWebDAVにアクセスするサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import xml.etree.ElementTree as ET | |
def filecheck(): | |
user = 'username' | |
password = 'password' | |
url = 'https://example.com/dav' | |
req = requests.Request('PROPFIND', url, headers={'Depth': '1'},auth=(user,password)) | |
prepped = req.prepare() | |
s = requests.Session() | |
resp = s.send(prepped) | |
root = ET.fromstring(resp.text) | |
files = [ f.text for f in root.findall('.//{DAV:}href') if f.text[-1] != '/' ] | |
if (files): | |
return files | |
else: | |
None | |
if __name__ == '__main__': | |
print(filecheck()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment