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: 
3
  • 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? Commented Dec 7, 2013 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. Commented Dec 7, 2013 at 22:42
  • related to the question title: Python running out of memory parsing XML using cElementTree.iterparse Commented Dec 8, 2013 at 0:43

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.