ICal feed via Django not recognized

I'm having a hard time creating a valid iCal stream using Django.

The problem I am facing is that my iCal file and stream are valid. I can visit the url of the stream to download the .ics file and check it only, import it into iCalendar or Google Calendar just fine, etc. In fact, if I host the same .ics file as the static file on my Django server, and subscribe to that static URL from Google Calendar, it works fine too. However, when you give Google Calendar the feed url, no luck.

I've seen a few similar Stack Overflow questions and when searching on Google, but most of them have the exact opposite problem (file doesn't work, stream doesn't work, or stream only works sometimes). Best of all I can tell from the code they suggest, I am doing something very similar, but my feed is not working, so I am missing something.

Here is the contents of the .ics file.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Tester//Version 0.0.1//EN
BEGIN:VEVENT
SUMMARY:iCal Timed
DTSTART:20140408T202000Z
DTEND:20140408T202000Z
DTSTAMP:20141107T153835Z
UID:event_1
DESCRIPTION:iCal Comment
END:VEVENT
BEGIN:VEVENT
SUMMARY:iCal All Day
DTSTART;VALUE=DATE:20140408
DTEND;VALUE=DATE:20140409
DTSTAMP:20141107T153835Z
UID:1
DESCRIPTION:iCal Comment
END:VEVENT
END:VCALENDAR

      

I am using Django 1.7 with icalendar 3.8.3 and below is the code used to create the feed.

def ical_feed(request):
    cal = icalendar.Calendar()
    cal.add('prodid', '-//Tester//Version 0.1.1//EN')
    cal.add('version', '2.0')

    for e in Event.events.filter(user_id=request.user.pk).iterator():
        event = icalendar.Event()
        event['uid'] = unicode(e.pk)
        ...
        cal.add_component(event)

    stream = cal.to_ical()

    response = HttpResponse(stream, content_type='text/calendar; charset=utf-8')
    response['Filename'] = request.user.username + '.ics'
    response['Content-Disposition'] = 'attachment; filename=' + request.user.username + '.ics'

    return response

      

It doesn't matter, but Django is served via Apache 2.4.7 (Ubuntu). Aside from setting Content-Type in my HttpResponse, is there something I need to do in Apache to get readers to see this as a stream? I have heard about django-ical and it seems like an unnecessary amount of overhead for what I am doing and looking at its code it sets up a response with headers just like I already do.

Any understanding would be greatly appreciated.

UPDATE

I misunderstood the UID, assuming it is a simple identifier for the items in my feed. However, this did not solve the problem. To clarify this issue, when trying to access my calendar using the iCal, iCalendar or Google Calendar feed validation engine, I was greeted with the error "iCal validation failed" and the calendar size always resulted in 0 bytes.

Jerry's suggestion for the CURL URL was correct. What I found was a little confusing, but I was so focused on code implantation that I never got to the Django level function. CURLing the URL showed 0 bytes were returned as the user was redirected to the / login page. I had an @login_required handler on my view.

Thanks a lot for your help, I am evaluating your answer correctly, Jerry, since it provided debugging, I needed to find a solution.

+3


source to share


1 answer


First, try looking at the headers from the client to see if the arent arents are mutilated or lost somewhere. You can use curl --head

then url to see the full headers that the client will receive on the same machine. (If you change cookie or agent based behavior, you can use the plugin or developer tools for that specific client to view the header information.)

Second, your UIDs are not unique in the universe. These UIDs could be duplicated elsewhere. One common practice is to add your own unique hostname to the UID to make sure they are unique.



Finally, you haven't specified how the feed crashes in Google Calendar and iCal. Is the feed just ignored as if it were empty? Is it a bug anyway? Or are the items displayed but not displayed correctly?

+2


source







All Articles