Python Forum

Full Version: could not build an URI from the schemaLocation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have inherited a Python script from my predecessor. However, it is failing with the error in the subject line. One thing that is making it difficult to debug (via logging statements) is its use of the lxml module, which was made using Cython.

I have tried making some changes to resolve the original error, which was slightly different. I have left the original in some comments below for reference.

_
SCHEMA_DOC = """
<xs:schema
    targetNamespace="http://www.isotc211.org/2005/gmi"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:gmi="http://www.isotc211.org/2005/gmi"
    xmlns:srv="http://www.isotc211.org/2005/srv">

    <xs:include
        schemaLocation="{install_root}/schema/gmi/gmi.xsd"/>
    <xs:import
        namespace="http://www.isotc211.org/2005/gml"
        schemaLocation="{install_root}/schema/gml/gml.xsd"/>
    <xs:import
        namespace="http://www.isotc211.org/2005/srv"
        schemaLocation="{install_root}/schema/srv/srv.xsd"/>

</xs:schema>
"""

    def __init__(self):
        """
        Load the 19115-2 schema so that every XML file produced is validated.
        """
        # Interpolate the path to the XSD files.
        path = pathlib.Path(__file__).parent / 'data'
        schema_doc = etree.fromstring(_SCHEMA_DOC)  # XML(_SCHEMA_DOC)  # .format(install_root=path.as_uri())
        # f = io.StringIO(schema_doc)
        self.schema = etree.XMLSchema(schema_doc)  # file=f
The error is

Error:
Traceback (most recent call last): File "/usr1/troberts/miniconda3/bin/rest2iso", line 11, in <module> load_entry_point('ags-metadata==0.1.0', 'console_scripts', 'rest2iso')() File "/usr1/troberts/miniconda3/lib/python3.8/site-packages/ags_metadata-0.1.0-py3.8.egg/ags_metadata/command_line.py", line 77, in rest2iso obj = NowCoastRestToIso(args.config, verbose=args.verbose) File "/usr1/troberts/miniconda3/lib/python3.8/site-packages/ags_metadata-0.1.0-py3.8.egg/ags_metadata/rest2iso.py", line 962, in __init__ super().__init__(config_file, verbose=verbose) File "/usr1/troberts/miniconda3/lib/python3.8/site-packages/ags_metadata-0.1.0-py3.8.egg/ags_metadata/rest2iso.py", line 107, in __init__ self.validator = Validator() File "/usr1/troberts/miniconda3/lib/python3.8/site-packages/ags_metadata-0.1.0-py3.8.egg/ags_metadata/validator.py", line 54, in __init__ self.schema = etree.XMLSchema(schema_doc) # file=f File "src/lxml/xmlschema.pxi", line 86, in lxml.etree.XMLSchema.__init__
Any suggestions?