Bug report #16333

Fetch WMTS fails in Python Console (with owslib) but works through QGIS widget

Added by geo julien over 7 years ago. Updated over 7 years ago.

Status:Closed
Priority:Normal
Assignee:Tom Kralidis
Category:Python plugins
Affected QGIS version:2.14.12 Regression?:No
Operating System:Windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:up/downstream
Crashes QGIS or corrupts data:No Copied to github as #:24243

Description

I'm working on my plugin which can add layers from OGC services directly to Map canvas without UI step. So I use owslib with PyQGIS. Trying various WMTS sample (check my script here: https://github.com/isogeo/isogeo-plugin-qgis/blob/master/test/test_wmts.py), I've found a WMTS that works through QGIS integrated widget but not from owslib (see attached screen capture), but not from Python script.

Just with version parameter (I know, quite useless but...):

wmts = WebMapTileService("http://data.geus.dk/arcgis/rest/services/OneGeologyGlobal/S071_G2500_OneGeology/MapServer/WMTS?request=GetCapabilities", version="1.0.0")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\wmts.py", line 114, in __init__
    self._buildMetadata(parse_remote_metadata)
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\wmts.py", line 133, in _buildMetadata
    self.provider=ServiceProvider(serviceprov)
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\ows.py", line 78, in __init__
    val = self._root.find(util.nspath('ProviderName', namespace))
AttributeError: 'NoneType' object has no attribute 'find'

With full parameters:

wmts = WebMapTileService("http://data.geus.dk/arcgis/rest/services/OneGeologyGlobal/S071_G2500_OneGeology/MapServer/WMTS?request=GetCapabilities", version="1.0.0", parse_remote_metadata=0, xml="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/1.0.0/WMTSCapabilities.xml")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\wmts.py", line 102, in __init__
    self._capabilities = reader.readString(xml)
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\wmts.py", line 649, in readString
    return etree.fromstring(st)
  File "C:\\OSGEO4~1\\apps\\Python27\\lib\\xml\\etree\\ElementTree.py", line 1300, in XML
    parser.feed(text)
  File "C:\\OSGEO4~1\\apps\\Python27\\lib\\xml\\etree\\ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "C:\\OSGEO4~1\\apps\\Python27\\lib\\xml\\etree\\ElementTree.py", line 1506, in _raiseerror
    raise err
ParseError: not well-formed (invalid token): line 1, column 5

Pointing only on the XML:

wmts = WebMapTileService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/1.0.0/WMTSCapabilities.xml")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\wmts.py", line 114, in __init__
    self._buildMetadata(parse_remote_metadata)
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\wmts.py", line 133, in _buildMetadata
    self.provider=ServiceProvider(serviceprov)
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\\owslib\\ows.py", line 78, in __init__
    val = self._root.find(util.nspath('ProviderName', namespace))
AttributeError: 'NoneType' object has no attribute 'find'

Behaviors should be the same, no? (sincere question)

qgis_214_osgeo4w_owslib_wmts.png (43.9 KB) geo julien, 2017-03-09 07:22 AM

History

#1 Updated by Tom Kralidis over 7 years ago

  • Resolution set to up/downstream
  • Status changed from Open to Closed

Suggest opening this as a pure OWSLib ticket (https://github.com/OWSLib/issues/new)

Also available in: Atom PDF