R
rbt
Has anyone used pure python to upload files to a webdav server over SSL?
I have no control over the server. I can access it with all of the
various webdav GUIs such as Konqueror, Cadaver, etc. by using a URL like
this:
webdavs://dav.hostname.com/user_name/uploads
My goal is to upload files automatically with a python script. The
server requires authentication over SSL which I can do with urllib2 like
this:
def auth_against_url(url, username, password):
# This is a slightly modified version that I found here:
# http://simon.incutio.com/archive/2004/07/15/instant
import urllib2
import base64
request = urllib2.Request(url)
b64 = base64.encodestring('%s:%s' % (username, password))[:-1]
request.add_header('Authorization', 'Basic %s' % b64)
try:
f = urllib2.urlopen(request)
print f.read()
f.close()
return True
except urllib2.HTTPError, e:
print e
return False
auth_against_url('https://dav.hostname.com/user_name/uploads',\
str.strip(raw_input('Enter User ID: ')),\
str.strip(raw_input('Enter Password: ')))
If urllib2 supported webdav, I think I'd be in business, but it doesn't.
Any one who can provide pointers on this? I've googled around to no
avail. I've began playing with Perl's HTTP:
AV and somone reccomended
PHP's curl functions as well, but I wanted to try this in Python first.
Many thanks,
rbt
I have no control over the server. I can access it with all of the
various webdav GUIs such as Konqueror, Cadaver, etc. by using a URL like
this:
webdavs://dav.hostname.com/user_name/uploads
My goal is to upload files automatically with a python script. The
server requires authentication over SSL which I can do with urllib2 like
this:
def auth_against_url(url, username, password):
# This is a slightly modified version that I found here:
# http://simon.incutio.com/archive/2004/07/15/instant
import urllib2
import base64
request = urllib2.Request(url)
b64 = base64.encodestring('%s:%s' % (username, password))[:-1]
request.add_header('Authorization', 'Basic %s' % b64)
try:
f = urllib2.urlopen(request)
print f.read()
f.close()
return True
except urllib2.HTTPError, e:
print e
return False
auth_against_url('https://dav.hostname.com/user_name/uploads',\
str.strip(raw_input('Enter User ID: ')),\
str.strip(raw_input('Enter Password: ')))
If urllib2 supported webdav, I think I'd be in business, but it doesn't.
Any one who can provide pointers on this? I've googled around to no
avail. I've began playing with Perl's HTTP:
PHP's curl functions as well, but I wanted to try this in Python first.
Many thanks,
rbt