The no_network argumenr to the XMLParser constructor does not seem to be working as described.

 

The following

import io

from lxml import etree

 

schema='''<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:paulhiggs:my-patch" elementFormDefault="qualified" attributeFormDefault="unqualified">

    <!-- Include patch operations from RFC5261 -->

    <include schemaLocation="https://www.iana.org/assignments/xml-registry/schema/patch-ops.xsd"/>

    <element name="Patch" type="PatchType"/>

    <!-- Patch -->

    <complexType name="PatchType">

        <choice minOccurs="1" maxOccurs="unbounded">

            <element name="add" type="add"/>

            <element name="remove" type="remove"/>

            <element name="replace" type="replace"/>

        </choice>

        <attribute name="paulsAttrib" type="string" use="required"/>

    </complexType>

</schema>

'''

 

parser=etree.XMLParser(load_dtd=True, no_network=False, huge_tree=True, resolve_entities=True)

s=etree.parse(io.StringIO(schema), parser)

my_schema=etree.XMLSchema(s)

 

yields an unexpected error

 

G:\lxml-test>python 10.py

Traceback (most recent call last):

  File "G:\lxml-test\10.py", line 28, in <module>

    my_schema=etree.XMLSchema(s)

  File "src\lxml\xmlschema.pxi", line 88, in lxml.etree.XMLSchema.__init__

lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}include': Failed to load the document 'https://www.iana.org/assignments/xml-registry/schema/patch-ops.xsd' for inclusion., line 3

 

 

If I curl -O https://www.iana.org/assignments/xml-registry/schema/patch-ops.xsd and change to <include schemaLocation=" patch-ops.xsd"/> the loading of the schema is successful

 

 

 

Just a thought: Might this be proxy- or https-related? Does it work if you locally serve the xs:included schema with http?

 

I *think* libxml2 respects http_proxy but I don’t know anything about https support.

 

Then maybe using s.th. else for the http(s) access to the resources (e.g. requests) could work;

I suspect one might need to use resolvers somehow for the “indirect” xs:include dependencies (https://lxml.de/resolvers.html).

 

Never done that myself so be just a wild guess. I could be totally wrong ;-).

 

Regards, Holger



     


Landesbank Baden-Wuerttemberg
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
HRA 12704
Amtsgericht Stuttgart
HRA 4356, HRA 104 440
Amtsgericht Mannheim
HRA 40687
Amtsgericht Mainz

Die LBBW verarbeitet gemaess Erfordernissen der DSGVO Ihre personenbezogenen Daten.
Informationen finden Sie unter https://www.lbbw.de/datenschutz.