1

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 ?

HenriC
  • 842
  • 8
  • 14
  • you ever got this to work? – Micromegas Mar 30 '20 at 16:10
  • This is very late, but check out https://stackoverflow.com/questions/60936116/ . I use ``https://mynextcloudinstanceurl/remote.php/dav/files/my_user_name/mydirectory/myfile.pdf`` . Then you have to write the returned content to a file like: ```if response.status_code == 200: with open("path/to/dir/file.pdf", 'wb') as file: file.write(response.content)``` – Micromegas Mar 30 '20 at 20:13

0 Answers0