[QGIS-Developer] Cannot load WMS capabilities from WMS provider in QGIS3 from python
David Marteau
dmarteau at 3liz.com
Mon Jan 15 09:27:58 PST 2018
Here is a test script that illustrate the problem a bit further: if we run createProvider() twice, the first time
the getCapbabilities will fail with a timeout. The second time, it will succeed.
If you run this script, clear the Qgis network cache between two invocations.
===================8<==============================
import os
import logging
from qgis.core import QgsApplication, QgsMessageLog
from qgis.core import QgsProject, QgsProviderRegistry
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# No Display
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
qgis_application = QgsApplication([], False )
qgis_application.setPrefixPath('/usr/local', True)
qgis_application.initQgis()
# Log any messages
def writelogmessage(message, tag, level):
arg = '{}: {}'.format( tag, message )
if level == QgsMessageLog.WARNING:
logger.warning(arg)
elif level == QgsMessageLog.CRITICAL:
logger.error(arg)
else:
logger.info <http://logger.info/>(arg)
messageLog = QgsApplication.messageLog()
messageLog.messageReceived.connect( writelogmessage )
wmsuri = ("contextualWMSLegend=0&crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/jpeg"
"&layers=s2cloudless&styles&tileMatrixSet=s2cloudless-wmsc-14"
"&url=http://tiles.maps.eox.at/wms? <http://tiles.maps.eox.at/wms?>" )
# GetCapabilities Fail with Request Timeout !!!
provider = QgsProviderRegistry.instance().createProvider( "wms", wmsuri )
# Run again => works !!!
provider = QgsProviderRegistry.instance().createProvider( "wms", wmsuri )
qgis_application.exitQgis()
del qgis_application
====================8<=============================
We have also tested simple QgsNetwork invocation from c++: tests shows that event loops have the running status, but the
request is not processed at the first invocation.
David
> Le 15 janv. 2018 à 15:05, David Marteau <dmarteau at 3liz.com> a écrit :
>
>>
>>
>>
>> Hi David,
>>
>> You need an event loop to use a Q(qg)NetworkAccessManager, it's asynchronous.
>>
>
> Hi Alessandro,
>
> Yes, we know that (see the second code in previous mail ): the QgsNetworkAccessManager works perfeclty in python, this is not the point.
>
> The point is: trying to instanciate a wmsprovider will issue a timeout when trying to request the capabilities: the code responsible for that creates its own QEventLoop and manage to do a blocking call (which is expected here).
> Please have a look at https://github.com/qgis/QGIS/blob/master/src/providers/wms/qgswmscapabilities.cpp#L1964 <https://github.com/qgis/QGIS/blob/master/src/providers/wms/qgswmscapabilities.cpp#L1964>. What we do not understand is why, despite the call of loop.exec() in the c++ code, the request is not processed (my example with the Q(gs)etworkAccessManager
> shows that it should processed)
>
> Actually you cannot instanciate properly a QgsProject with a WMS layer.
>
> To convince yourself, try to instanciate a QgsProject in python (in a standalone python script) from a .qgs project having a single wms layer: it will fail to instanciate the layer.
>
>>
>>
>> --
>> Alessandro Pasotti
>> w3: www.itopen.it <http://www.itopen.it/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180115/070f8ead/attachment-0001.html>
More information about the QGIS-Developer
mailing list