Python 2.6 WebDAV and JungleDisk

The Python2.6 problem

A while ago, I discovered that JungleDisk allows you to access your directories through WebDAV. This opens up a wide range of opportunities, as our entire company currently uses JungleDisk to store and create reports in Excel.

I currently have a simple Python script which allows me to dump data out of Amazon SimpleDB into CSV files, and store the results into JungleDisk for our Financial team to generate reports in Excel. The same thing could be done to generate Excel files using XLWT if needed.

With Mac OS 10.6, python was upgraded to Python2.6 from Python2.5. I welcomed this change greatly as Ubuntu also made a similar move. What I didn't know, however, was that the Library I was using to communicate to my JungleDisk WebDAV server (PyDAV) was incompatible with Python2.6 due to some recent SSL changes. I like PyDAV a lot, so I found a forked copy of it on bitbucket. I decided to go at it and fix what was broken for Python2.6.

This turned out to be quite a simple fix and I even submitted a patch so you too can have PyDAV working with Python2.6! Essentially all you have to do is change a few lines in WebDAV/httplib0.py:

def connect(self, host, port=0):
"Connect to a host on a given (SSL) port."
+ import ssl
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
- ssl = socket.ssl(sock, self.key_file, self.cert_file)
- self.sock = FakeSocket(sock, ssl)
+ self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)


def test():


With these minor changes, you can once again use PyDAV with Python2.6.

Connecting to JungleDisk

JungleDisk maintains a working WebDAV server available at:
https://[your-account-name].legacy.myjungledisk.com/[folder-name]

Connecting to this account is as simple as creating a new Resource and traversing it:

from WebDAV import client
res = client.Resource("https://myaccountname.legacy.myjungledisk.com/myfolder",
username="myuser", password="mypassword")
mysubfolder = res['mysubfolder']
myfile = res['myfile.txt']


You can create a new folder by running mkcol:

mynewfolder = res['mynewfolder']
mynewfolder.mkcol()


And upload files by:

mynewfile = mynewfolder['newfile.txt']
mynewfile.put(file="String Data for this file")


You can also do many other WebDAV related tasks, but this should help you cover the basics. You should now be able to place your new files directly into your JungleDisk account via a simple python script!

Comments