<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Here is a test script that illustrate the problem a bit further: if we run createProvider() twice, the first time <div class="">the getCapbabilities will fail with a timeout. The second time, it will succeed. </div><div class=""><br class=""></div><div class="">If you run this script, clear the Qgis network cache between two invocations. </div><div class=""><div class=""><br class=""></div><div class=""><div class="">===================8<==============================</div><div class=""><div class="">import os</div><div class="">import logging</div><div class=""><br class=""></div><div class="">from qgis.core import QgsApplication, QgsMessageLog</div><div class="">from qgis.core import QgsProject, QgsProviderRegistry</div><div class=""><br class=""></div><div class="">logger = logging.getLogger()</div><div class="">logger.setLevel(logging.DEBUG)</div><div class=""><br class=""></div><div class=""># No Display</div><div class="">os.environ['QT_QPA_PLATFORM'] = 'offscreen'</div><div class=""><br class=""></div><div class="">qgis_application = QgsApplication([], False )</div><div class="">qgis_application.setPrefixPath('/usr/local', True)</div><div class="">qgis_application.initQgis()</div><div class=""><br class=""></div><div class=""># Log any messages</div><div class="">def writelogmessage(message, tag, level):</div><div class="">    arg = '{}: {}'.format( tag, message )</div><div class="">    if level == QgsMessageLog.WARNING:</div><div class="">        logger.warning(arg)</div><div class="">    elif level == QgsMessageLog.CRITICAL:</div><div class="">        logger.error(arg)</div><div class="">    else:</div><div class="">        <a href="http://logger.info" class="">logger.info</a>(arg)</div><div class=""><br class=""></div><div class="">messageLog = QgsApplication.messageLog()</div><div class="">messageLog.messageReceived.connect( writelogmessage )</div><div class=""><br class=""></div><div class="">wmsuri = ("contextualWMSLegend=0&crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/jpeg"</div><div class="">          "&layers=s2cloudless&styles&amp;tileMatrixSet=s2cloudless-wmsc-14"</div><div class="">          "&url=<a href="http://tiles.maps.eox.at/wms?" class="">http://tiles.maps.eox.at/wms?</a>" )</div><div class=""><br class=""></div><div class=""># GetCapabilities Fail with Request Timeout !!!</div><div class="">provider = QgsProviderRegistry.instance().createProvider( "wms", wmsuri )</div><div class=""><br class=""></div><div class=""># Run again => works !!!</div><div class="">provider = QgsProviderRegistry.instance().createProvider( "wms", wmsuri )</div><div class=""><br class=""></div><div class="">qgis_application.exitQgis()</div><div class="">del qgis_application</div></div><div class="">====================8<=============================</div><div class=""><br class=""></div><div class="">We have also tested simple QgsNetwork invocation from c++: tests shows that event loops have the running status, but the </div><div class="">request is not processed at the  first invocation.</div><div class=""><br class=""></div><div class="">David</div><div class=""><br class=""></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div></div></div><div><blockquote type="cite" class=""><div class="">Le 15 janv. 2018 à 15:05, David Marteau <<a href="mailto:dmarteau@3liz.com" class="">dmarteau@3liz.com</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><br class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Hi David, <br class=""></div><div class=""><br class=""></div><div class="">You  need an event loop to use a Q(qg)NetworkAccessManager, it's asynchronous.<br class=""></div><div class=""><br class=""></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Hi Alessandro,</div><div class=""><br class=""></div><div class="">Yes, we know that (see the second code in previous mail  ):  the  QgsNetworkAccessManager works perfeclty in python, this is not the point.</div><div class=""><br class=""></div><div class="">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). </div><div class="">Please have a look at <a href="https://github.com/qgis/QGIS/blob/master/src/providers/wms/qgswmscapabilities.cpp#L1964" class="">https://github.com/qgis/QGIS/blob/master/src/providers/wms/qgswmscapabilities.cpp#L1964</a>.  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</div><div class="">shows that it should processed)</div><div class=""><br class=""></div><div class="">Actually you cannot instanciate properly a QgsProject with a WMS layer.</div><div class=""><br class=""></div><div class="">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.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><br clear="all" class=""></div><br class="">-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature">Alessandro Pasotti<br class="">w3:   <a href="http://www.itopen.it/" target="_blank" class="">www.itopen.it</a></div>
</div></div>
</blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>