I want to load a WMS with PyQGIS. I know this is possible on version 2.18 If it is done with the graphical Interface by checking on the Use contextual WMS legend
Now I manage to load a WMS with PyQGIS but I can not figure how to load the WMS and its legend.
Below there is partial working code snippet:
urlWithParams = "url=http://localhost:8080/geoserverwww.geoportaligm.gob.ec/sf50k/wms&format=image/png&layers=sfdem&styles=&crs=EPSGpng&layers=igm:26713"acequia_l&styles=&crs=EPSG:32717"
rlayer = QgsRasterLayer(urlWithParams, 'testing', 'wms')
rlayer.isValid()
QgsMapLayerRegistry.instance().addMapLayer(rlayer)