[Python] Error 'failed to load external entity' when using Python lxml

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to parse an XML document I retrieve from the web, but it crashes after parsing with this error:

    ': failed to load external entity "<?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="GreenButtonDataStyleSheet.xslt"?>


    That is the second line in the XML that is downloaded. Is there a way to prevent the parser from trying to load the external entity, or another way to solve this? This is the code I have so far:

    import urllib2
    import lxml.etree as etree

    file = urllib2.urlopen("http://www.greenbuttondata.org/data/15MinLP_15Days.xml")
    data = file.read()
    file.close()

    tree = etree.parse(data)

    Continue reading...

Compartilhe esta Página