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