[icalendar-dev] iCalendar cannot parse file

Max M maxm at mxm.dk
Mon May 1 13:39:44 CEST 2006


Markus Gritsch wrote:

> Hi,
>
> I downloaded the iCalendar 0.11 package and tried to use it for 
> reading an .ics file exported from OpenGroupware.  Unfortunately the 
> parser failed with the following exception:
>
> Traceback (most recent call last):
>     File "test.py", line 2, in ?
>       cal = Calendar.from_string(open('_synedra_mgr.ics','rb').read())
>     File "C:\Python24\lib\site-packages\icalendar\cal.py", line 342, 
> in from_string
>       name, params, vals = line.parts()
>     File "C:\Python24\lib\site-packages\icalendar\parser.py", line 
> 406, in parts
>       raise ValueError, 'Content line could not be parsed into parts' 
> ValueError: Content line could not be parsed into parts
>
> Has someone an idea how to fix the parser?


You should fix your data instead.

When I print out the keynames I get this:

name BEGIN
name METHOD
name PRODID
name VERSION
name BEGIN
name LOCATION
name STATUS
name SUMMARY
name DESCRIPTION
name \n
Traceback (most recent call last):
  File "E:\maxm\pys\x.py", line 6, in ?
    cal = icalendar.Calendar.from_string(open('x.ics','rb').read())
  File "C:\Python24\lib\site-packages\icalendar\cal.py", line 342, in 
from_string
    name, params, vals = line.parts()
  File "C:\Python24\lib\site-packages\icalendar\parser.py", line 398, in 
parts
    validate_token(name)
  File "C:\Python24\lib\site-packages\icalendar\parser.py", line 42, in 
validate_token
    raise ValueError, name
ValueError: \n

This means that the file has a '\n' as a keyname. Which is illegal.

Looking into your ics file I can see:

DESCRIPTION:Der Termin für´s Fahrsicherheitstraining steht jetzt\, ist 
zwar ein Bissi später als erwartet\, aber dann dafür dort sicher schon 
sehr frühlingshaft...
\n
\nBitte pünktlich um spätestens 09:30 auftauchen!

Here there is an illegal fold. "a fold is carriage return followed by 
either a space or a tab" And as you can see, there is no space or tab 
before the '\n', which is the problem. It fools the parser into thinking 
it is a key.

It should look like this to be legal:

DESCRIPTION:Der Termin für´s Fahrsicherheitstraining steht jetzt\, ist 
zwar ein Bissi später als erwartet\, aber dann dafür dort sicher schon 
sehr frühlingshaft...
 \n
 \nBitte pünktlich um spätestens 09:30 auftauchen!

Notice the leading space character.

or more correctly like:

DESCRIPTION:Der Termin für´s Fahrsicherheitstraining steht jetzt\, ist zwar
 ein Bissi später als erwartet\, aber dann dafür dort sicher schon sehr frü
 hlingshaft...\n\nBitte pünktlich um spätestens 09:30 auftauchen!


Feel free to post a bug report to OpenGroupware.

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96




More information about the icalendar-dev mailing list