I'm trying to list files using webdab but I'm having issues. I can create directories and put files just fine but not list a directory or pull a file. I'm seeing the error, "Method not supported".
from webdav3.client import Client
options = {
'webdav_hostname': "https://___________.com/remote.php/dav/files/",
'webdav_login': "user_name",
'webdav_password': "password"
}
client = Client(options)
print(client.list('/'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/<user>/.local/lib/python3.10/site-packages/webdav3/client.py", line 67, in _wrapper
res = fn(self, *args, **kw)
File "/home/<user>/.local/lib/python3.10/site-packages/webdav3/client.py", line 264, in list
response = self.execute_request(action='list', path=directory_urn.quote())
File "/home/<user>/.local/lib/python3.10/site-packages/webdav3/client.py", line 228, in execute_request
raise MethodNotSupported(name=action, server=self.webdav.hostname)
webdav3.exceptions.MethodNotSupported: Method 'list' not supported for https://________.com/remote.php/dav/files
The client.list()
method assumes the remote root directory by default.
As you supply https://___________.com/remote.php/dav/files/
as your webdav_hostname
the root directory it tries to access when you call client.list('/')
is the top level files directory. As a Nextcloud user you don't have access to that level, so listing that is impossible. However, you do have access to the files/<username>
directory, so listing client.list('/<username>/')
works.
To prevent that you have prepend the username to every list command you can set the webdav_hostname
to .../remote.php/dav/files/<username>
. Then a call to client.list()
should work straight away.