I have a markdown file on a NextCloud 15 server, in MyDirectory/
.
So far I've been able to list MyDirectory/
content, despite the fact that documentation is not very consistent with what is actually working.
For example, I'm using https://cloud.example.com/remote.php/webdav/folder
instead of https://cloud.example.com/remote.php/dav/files/username/folder
as said in the doc. My (working) code:
import requests
import xmltodict
webdav_options = """<?xml version="1.0" encoding="UTF-8"?>
<d:propfind xmlns:d="DAV:">
<d:prop xmlns:oc="http://owncloud.org/ns">
<d:getlastmodified/>
<d:getcontenttype/>
<oc:fileid/>
</d:prop>
</d:propfind>"""
r = requests.request('PROPFIND', 'https://my-domain.com/nextcloud/remote.php/webdav/MyDirectory',
auth=('username', 'password'),
data=webdav_options
)
xml_dict = xmltodict.parse(r.text, dict_constructor=dict)
for response in xml_dict['d:multistatus']['d:response']:
filename = unquote(response['d:href']).replace(
'/nextcloud/remote.php/webdav/', '')
print(filename) # Working great
Now I would like to download the files. Following the documentation found here is not working... Trying this only downloads an html page:
url = f'https://my-domain.com/nextcloud/remote.php/webdav/MyDirectory/{filename}'
my_file = requests.get(url, auth=(usernanme, password))
print(my_file.content) # html content
Any idea how to proceed ?