lkiesow / python-feedgen

Python module to generate ATOM feeds, RSS feeds and Podcasts.
https://feedgen.kiesow.be/
BSD 2-Clause "Simplified" License
713 stars 123 forks source link

Non-Zero Integer for enclosure length causes type error #104

Closed drrm closed 7 months ago

drrm commented 3 years ago

Attached is a file that causes a type error when rss_str is called.

Traceback (most recent call last):

  File "c:\Users\DavidMck\Documents\feedgen-test1.py", line 14, in <module>
    fg.rss_str(pretty=True)
  File "C:\Program Files\Python38\lib\site-packages\feedgen\feed.py", line 398, in rss_str
    feed, doc = self._create_rss(extensions=extensions)
  File "C:\Program Files\Python38\lib\site-packages\feedgen\feed.py", line 374, in _create_rss
    item = entry.rss_entry()
  File "C:\Program Files\Python38\lib\site-packages\feedgen\entry.py", line 247, in rss_entry
    enclosure.attrib['length'] = self.__rss_enclosure['length']
  File "src\lxml\etree.pyx", line 2429, in lxml.etree._Attrib.__setitem__
  File "src\lxml\apihelpers.pxi", line 593, in lxml.etree._setAttributeValue
  File "src\lxml\apihelpers.pxi", line 1538, in lxml.etree._utf8
TypeError: Argument must be bytes or unicode, got 'int'

The problem is this call to enclosure - fe.enclosure('http://lernfunk.de/media/654321/1/file.mp3', 100, 'audio/mpeg') if 100 is passed as a string - "100" - the error does not occur. The call in lxml.etree expects the value to be a string.

feedgen-test1.py.txt

Certainly one could change the call to enclosure, but it seems that ideally a "length" variable would allow an integer value.