skshetry / webdav4

WebDAV client library with a fsspec based filesystem and a CLI.
https://skshetry.github.io/webdav4
MIT License
66 stars 16 forks source link

Can't access files on Netfile #134

Open beccon4 opened 2 years ago

beccon4 commented 2 years ago

I try to download a file from a Netfile "Data Room" which is a WebDAV share. The URL is https://webdav.netfiles.de//projectfiles. When using other WebDAV clients such as Gnome's Files application, I am able to list the directory and upload/download files. Unfortunately doing so using webdav4 fails. I can show the file content (ls) but when trying to access that file I get a "not found" error:

#!/bin/python3
from webdav4.client import Client
netfile_client = Client("https://webdav.netfiles.de/***changed***/projectfiles", auth=("myemail@address.xy", "secret"))

print ("This works: client.ls('/hallo.txt') " , netfile_client.ls("/hallo.txt"))

print ("This fails: client.content_type('/hallo.txt')" , netfile_client.content_type("/hallo.txt"))

results in:

$ ./get_netfiles.py 
This works: client.ls('/hallo.txt')  [{'name': 'hallo.txt', 'href': 'https://webdav.netfiles.de/***changed***/projectfiles/hallo.txt', 'content_length': 12, 'created': datetime.datetime(2022, 10, 26, 15, 46, 10, tzinfo=tzutc()), 'modified': datetime.datetime(2022, 10, 26, 15, 46, 10, tzinfo=datetime.timezone.utc), 'content_language': None, 'content_type': 'text/plain; charset=utf-8', 'etag': '"36b787591eb370bb0c9047dc1e2e6e20"', 'type': 'file', 'display_name': 'hallo.txt'}]
Traceback (most recent call last):
  File "/home/beccon/Python/./get_netfiles.py", line 9, in <module>
    print ("This fails: client.content_type('/hallo.txt')" , netfile_client.content_type("/hallo.txt"))
  File "/usr/local/lib/python3.10/dist-packages/webdav4/client.py", line 581, in content_type
    return self.get_props(path, "content_type").content_type
  File "/usr/local/lib/python3.10/dist-packages/webdav4/client.py", line 334, in get_props
    result = self.propfind(path, headers=headers, data=data)
  File "/usr/local/lib/python3.10/dist-packages/webdav4/client.py", line 318, in propfind
    http_resp = self.with_retry(call)
  File "/usr/local/lib/python3.10/dist-packages/webdav4/func_utils.py", line 44, in wrapped_function
    return func()
  File "/usr/local/lib/python3.10/dist-packages/webdav4/func_utils.py", line 68, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/webdav4/client.py", line 365, in _request
    raise ResourceNotFound(path)
webdav4.client.ResourceNotFound: The resource /hallo.txt could not be found in the server

The same happens when I use the cli command dav.

For some strange reason everything works fine when I connect to Nextcloud. There I can list the directory, show file attributes, upload and download:

./get_nextcloud.py 
This works [{'name': 'hallo.txt', 'href': '/nextcloud/remote.php/dav/files/test001/hallo.txt', 'content_length': 17, 'created': None, 'modified': datetime.datetime(2022, 10, 26, 17, 55, 57, tzinfo=datetime.timezone.utc), 'content_language': None, 'content_type': 'text/plain', 'etag': '"dbcd4f45a05b94992167db7b36b0838b"', 'type': 'file', 'display_name': None}]
This works also text/plain
Upload
Download

An interesting difference is that in Nexcloud the href does not contain an FQDN.