Skip to content

Instantly share code, notes, and snippets.

@tsuemura
Last active March 28, 2021 14:50
Show Gist options
  • Save tsuemura/0d26aff99990fd483430c3639fee48a1 to your computer and use it in GitHub Desktop.
Save tsuemura/0d26aff99990fd483430c3639fee48a1 to your computer and use it in GitHub Desktop.
PythonでBasic認証付きのWebDAVにアクセスするサンプル
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