2

I'm using python version 2.7.* and i need to get youtube playlist. I do it like this:

import urllib
from xml.dom import minidom

playlist_xml = str(urllib.urlopen('https://gdata.youtube.com/feeds/api/playlists/PLKwibIpsTqDyV6NgiJmO-x0yKfqWjApwp?v=2').read())
playlist = minidom.parse(playlist_xml)

The problem is that i can't parse the result…

Traceback (most recent call last):
  File "/Users/Python/parser.py", line 11, in <module>
    playlist = minidom.parse(playlist_xml)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/minidom.py", line 1914, in parse
    return expatbuilder.parse(file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py", line 922, in parse
    fp = open(file, 'rb')
IOError: [Errno 63] File name too long: 
alko
  • 46,136
  • 12
  • 94
  • 102
user1692333
  • 2,461
  • 5
  • 32
  • 64
  • There are ways to parse unmanageably long XML documents as a stream in python but this is not a particularly large document. How is the parse call failing? What were you expecting? – Tom McClure Dec 07 '13 at 22:42
  • 1
    "I can't parse the result" is not a very descriptive statement of the problem. Have you looked at the xml you're trying to parse? Does it raise an error? If so, what is it? I doubt very much that this has to do with the size of the XML. Youtube's API only allows 50 results to be returned at a time (I think), so the xml shouldn't be that big. – mgilson Dec 07 '13 at 22:42
  • related to the question title: [Python running out of memory parsing XML using cElementTree.iterparse](http://stackoverflow.com/q/7697710/4279) – jfs Dec 08 '13 at 00:43

1 Answers1

3

You should use parseString method of minidom instead of parse. While parseString parses XML, and accepts a string, parse accepts filename_or_file, and fails treating XML content as a file name.

playlist = minidom.parseString(playlist_xml)
alko
  • 46,136
  • 12
  • 94
  • 102