How to get error when QgsVectorLayer is not valid

by Luca Guida   Last Updated September 14, 2018 15:22 PM

In QGIS 2.18.16, with a custom plugin, i tried this code to create a new vector layer for WFS:

v_layer = QgsVectorLayer(uri.uri(), "my WFS layer", "WFS", False)
if not v_layer.isValid():
    print v_layer.error()            # 1
    print v_layer.error().message()  # 2
    print v_layer.error().summary()  # 3
  • print 1: is a qgis._core.QgsError object
  • print 2: empty string
  • print 3: qgis crash with segmentation fault

I need to get a error type or the wfs response, to understand for example if the url is not correct or if the service is down

Any ideas? Thanks!



Related Questions