views:

72

answers:

1

Hello everyone,

I'm trying to access Apples iCal-Server on a Mac OS X Snow Leopard Server via Python. The server is up and running and working with it via the iCal-Application is just fine. Now I need to access this server via Python to use it as backend for resource planning. I have already looked at the CalDav-Module (http://packages.python.org/caldav/index.html) but the sample provided there didn't find any calendar, although the Principal-URL is correct.

So how can I read the events within a time range from a user's calendar using python?

A: 

[Not a solution but to debug]

From the example given in the caldav module documentation:

from datetime import datetime
import caldav
from caldav.elements import dav, cdav

# Principal url
url = "https://user:pass@hostname/user/Calendar"

client = caldav.DAVClient(url)
principal = caldav.Principal(client, url)
calendars = principal.calendars()

Issues

  1. The url example is not the principal url for ical server
  2. if you look at the code for calendars = principal.calendars(), it ignores the response.
  3. If your principal url is incorrect then without issuing any errors it will return just an empty set of calendars.

Debugging help:

in file objects.py, there is a method for DAVObject called children. You can modify the code to include some debugging information. If you can paste the following and also paste your information in the question.

    response = self.client.propfind(self.url.path, body, depth)
    print response, self.url.path #provide additional info
    print response.raw  #provide additional info
    for r in response.tree.findall(dav.Response.tag):
pyfunc
Thank you very much for the answer, it was very helpful while debugging. Actually I had installed version caldav 0.1.4, for which the documentation was written. After downloading the source of 0.1.6 and adding the print-commands, it suddenly worked. So I think there's something fixed that prevented the 0.1.4 from connecting to the calendarserver.
Hive
@Hive: It would be nice if you can put your principal url here.
pyfunc
I tried this URL: http://admin:[email protected]:8008/principals/__uids__/admin/ which I found as principal URL when accessing the Address in my browser. But using it, no calendars are found. It kind of worked with this URL: http://admin:[email protected]:8008/calendars/users/admin/ so I got all calendars for the user admin (2 * caldav.objects.Calendar), but actually all operations like date_search, etc. on each of this calendars result in an httplib.CannotSendRequest and the properties like name are None.
Hive
@Hive: I hope my answer helped. To explain why principal url did not work. The issue is with library. It does not change the url while querying for calendars. the second url is the way to query all calendars. Let me know the specifics and may be I can try out.
pyfunc
Because of the issues with the Library I've searched for other ones and currently try this: trac.calendarserver.org/wiki/CalDAVClientLibrary where I can enable HTTP-Logging. Then went to the CalDAVClientLibrary directory, started the python console and tried: import client.account myclient = client.account.CalDAVAccount(server="192.168.1.170", port=8008, user="myuser", pswd="password", principal="myuser", logging=True). In the Browser I can go to 192.168.1.170:8008/principals/users/myuser or to the calendar-URL but in Python I find in the Principal propstat resp status 404
Hive
Okay, actually the parameter principal needs a full URL and not the principals name. So it is client.account.CalDAVAccount(server="192.168.1.170", port=8008, user="myuser", pswd="password", principal="/principals/users/myuser", logging=True)
Hive