Reputation: 13254
I want to write a script to connect and access a webdav server. I found out that there is a
/usr/local/lib/python2.7/dist-packages/davlib.py
But how to use it? There is no tutorial, no documentation and nothing to google. Anybody able to write a small hello world for it?
the test webdav server is on localhost:80/webdav
and there is a davtest.txt
file with the word dav
inside.
$ cd <path_to_webdav>
$ ls
davtest.txt
$ cat davtest.txt
dav
I can read python, so if I could just connect and read that there is a file called davtest.txt
or maybe even it's content I think I could get started working with the source. Not knowing how webDAV works and not knowing davlib.py
both together is quite tough, though.
Upvotes: 0
Views: 589
Reputation: 1802
To do a simple get request using davlib
import davlib
import base64
host = 'myhost'
protocol = 'myprotocol'
username = 'myusername'
password = 'mypassword'
url = '{}://{}/{}'.format(protocol, host, some_file_path)
d = davlib.DAV(protocol=myprotocol, host=myhost)
auth_token = base64.encodestring('%s:%s' %(username, password)).strip()
header = {"Authenication": "Basic %s' %auth_token}
d.get(url,header)
Basic authentication is usable only on https. For more (dry) details on webDAV, see the RFC.
The most mature webDAV client library I've found is python-webdav-library
Upvotes: 0
Reputation: 13254
With webdav-lib I could solve that problem:
url = "davs://localhost:80/webdav/davtest.txt"
r = ResourceStorer(url)
result = r.downloadContent().read()
Upvotes: 1