django-ical
django-ical copied to clipboard
Example is not working.
- Django 3.2.4
- Python 3.9
How to reproduce:
Run the example:
from django_ical import feedgenerator
feed = feedgenerator.ICal20Feed(
title="My Events",
link="http://www.example.com/events.ical",
description="A iCalendar feed of my events.",
language="en",
)
feed.add_item(
title="Hello",
link="http://www.example.com/test/",
description="Testing.",
start_datetime=datetime(2012, 5, 6, 10, 00),
end_datetime=datetime(2012, 5, 6, 12, 00),
)
fp = open('test.ical', 'w')
feed.write(fp, 'utf-8')
fp.close()
Output:
>>> feed.write(fp, 'utf-8')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "some-path/venv/lib/python3.9/site-packages/django_ical/feedgenerator.py", line 100, in write
outfile.write(to_ical())
TypeError: write() argument must be str, not bytes
>>> cal = Calendar()
>>> cal.add("version", "2.0")
>>> cal.add("calscale", "GREGORIAN")
>>> cal.to_ical()
b'BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n'
This is what I found when calling the to_ical()
function.
Fix suggestion:
Change the example to be fp = open('test.ical', 'wb')
instead.
@phsetti I tried what you did, with the example code. But This still gets me a zero bytes ics file..
Can we get any eyes on this? @aleksihakli or any other relevant
- Django 3.2.11
- Python 3.9.10
feed = feedgenerator.ICal20Feed(
title="My Events",
link="http://www.example.com/events.ical",
description="A iCalendar feed of my events.",
language="en",
)
feed.add_item(
title="Hello",
link="http://www.example.com/test/",
description="Testing.",
start_datetime=datetime(2012, 5, 6, 10, 00),
end_datetime=datetime(2012, 5, 6, 11, 00)
)
fp = open("test.ics", "w")
feed.write(fp, "utf-8")
response = HttpResponse(content_type='text/calendar')
response['Filename'] = 'filename.ics' # IE needs this
response['Content-Disposition'] = 'attachment; filename=filename.ics'
return response
Error:
Traceback (most recent call last):
...
feed.write(fp, "utf-8")
File "/Users/thorbenluepkes/work/newmarkets/venv/lib/python3.9/site-packages/django_ical/feedgenerator.py", line 100, in write
outfile.write(to_ical())
TypeError: write() argument must be str, not bytes
Also, the docs are missing a ,
after description="Testing."
Would you be interested in opening a PR that fixes the example to use the correct file mode so the example works with Python 3?