<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">We hit a very nasty problem when trying to load projects with wms layer defined from python: loading capabilities fail with timeout error, thus preventing creating any project or layer from python.</div><div class=""><br class=""></div><div class="">The problem has been verified in Debian, Ubuntu and fresh OSX build from master branch.</div><div class=""><br class=""></div><div class="">We have somehow been able to reduce the problem to the loading of the wmsprovider. The following python code provide a minimal example for reproducing the problem:</div><div class=""><br class=""></div><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=""><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=""># Request Timeout</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="">This fail with the following qgis errors</div><div class=""><br class=""></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">WMS: Download of capabilities failed: Operation canceled</div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Network: Network request <a href="https://tiles.maps.eox.at/wms?SERVICE=WMS&REQUEST=GetCapabilities" class="">https://tiles.maps.eox.at/wms?SERVICE=WMS&REQUEST=GetCapabilities</a> timed out</div></div><div class=""><br class=""></div><div class="">Note that the following piece of code work perfectly and proceed the request without problems:</div><div class=""><br class=""></div><div class="">==============================================================</div><div class="">from PyQt5.QtCore import QUrl, QEventLoop</div><div class="">from PyQt5.QtNetwork import QNetworkRequest</div><div class=""><br class=""></div><div class="">url = QUrl("<a href="https://tiles.maps.eox.at/wms?SERVICE=WMS&REQUEST=GetCapabilities" class="">https://tiles.maps.eox.at/wms?SERVICE=WMS&REQUEST=GetCapabilities</a>")</div><div class=""><br class=""></div><div class="">request = QNetworkRequest()</div><div class="">request.setUrl(url)</div><div class="">manager = QgsNetworkAccessManager.instance()</div><div class="">replyObject = manager.get(request)</div><div class=""><br class=""></div><div class="">loop = QEventLoop()</div><div class="">def onfinish(  ):</div><div class="">    print("Qt Return Code:",replyObject.attribute(QNetworkRequest.HttpStatusCodeAttribute))</div><div class="">    answer = replyObject.readAll();</div><div class="">    print(answer[:200],"\n")</div><div class="">    loop.quit()</div><div class=""><br class=""></div><div class="">replyObject.finished.connect( onfinish )</div><div class="">loop.exec()</div><div class="">==============================================================</div><div class=""><br class=""></div><div class="">So this is not fundamentally a problem with the network manager.</div><div class=""><br class=""></div><div class="">At this point we are stuck because the provider do not do something fundamentally different from the last piece of code, </div><div class=""><br class=""></div><div class="">In qgis code the request execution stall 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></div><div class=""> </div><div class="">The problem does not occur if we run the project from the Desktop application: we think that there is a problem with the QEventLoop execution but we have no clue atm to check this assumption.</div><div class=""><br class=""></div><div class="">So if anybody have any idea on the subject…...</div><div class=""><br class=""></div><div class="">Regards</div><div class="">David</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>