-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot load WMS capabilities from WMS provider in QGIS3 from standalone python #25761
Comments
Author Name: Alessandro Pasotti (@elpaso) I suspect that a main event loop is required for a proper execution of the signals and slots in the network access manager, please have a look to the attached working test case. But I still don't know why :(
|
Author Name: David Marteau (@dmarteau) I do not think this is totally right since after the first attempt (which fail) then things appears to be ok: IHMO there is some kind of init state condition concerning event loop which is not set on first run. Anyway, runnig app.exec will defeat the purpose of embedding since it introduce a blocking state. |
Author Name: Alessandro Pasotti (@elpaso) Well, I don't really know what you're trying to do, but in QGIS application you do have a running main event loop and this is not an issue. If you have a standalone non-GUI script that must run without an event loop you need a blocking condition or your script might terminate before the network reply comes back. In any case you need an event loop (main or local). Btw, in theory this whole thing should work without a main event loop because in the wms capabilities code there is a local event loop running, whose purpose is exactly to turn an asynchronous operation into a blocking one, what I don't understand is why it works the second time, I believe that the answer is in Qt QNetworkAccessManager core code, I don't see any obvious issue in QgsNetworkAccessManager or in the WMS code. Just curious, was it working in 2.x ?
|
Author Name: David Marteau (@dmarteau) Alessandro Pasotti wrote:
This is true for desktop. This is not true for server: in the fcgi implementation the main loop is a fcgi loop which is not related
Yes
Yes
Exactly
In fact, this is the way it should work in the normal way: as you said it, because of the the local event, it should not block the first time.
Me neither, I have spent some time to check the c++ code and I did not see anything suspicious.
This has to be checked, and it has to be checked also in the fcgi implementation of the Qgis3 server. |
Author Name: Alessandro Pasotti (@elpaso) I've translated the (failing) python test to C++ and it passes ... that's wierd.
That's pointing us towards the initialization code in QGIS application: initQGIS doesn't do all the stuff...
|
Author Name: Alessandro Pasotti (@elpaso) The test works fine in 2.x so it's a regression
|
Author Name: Alessandro Pasotti (@elpaso)
|
Author Name: Alessandro Pasotti (@elpaso) I did some more research with different endpoints and I've discovered something really confusing, I now believe that we hit a Qt bug.
For example (same server):
So, we can assume that there is something going bad with hostname resolution, every time I use the IP address it works and it fails when using the hostname (of course I verified with a browser that all the getcapabilities URLs were working). |
Author Name: Alessandro Pasotti (@elpaso) Further info: a DNS look up prior to the connection works (Note: Since Qt 4.6.3 QHostInfo is using a small internal 60 second DNS cache for performance improvements.)
|
Author Name: David Marteau (@dmarteau) Allessandro, thanks for investigating this. So you think that it is related to DNS ? For information, In my tests, wathever the url given in the first call but all subsequent call on différent hostname were successful: I have tested this by first calling with a 'localhost' - which has no wms service at all, but fail with timeout, then doing other calls to - say 'tiles.maps.eox.at' - are all successfull. So could we have a scenario where the DNS resolver is not correctly available/initialized for network opération at the first call and available for all subsequent calls ? |
Author Name: Alessandro Pasotti (@elpaso)
I suspect it is related with QHostInfo::lookupHost() which is called by QAbstractSocketPrivate, there are a lot of signal-slot connections that being in a separate thread are probably bound to the GUI thread loop (which isn't running in our test cases) for a correct dispatch and delivery. Still this doesn't explain why subsequent calls on different hostnames works after the first fails.
I admit that I don't have a clear picture but yes, I think that DNS lookup initialization might be involved. Would you please confirm that using an IP address instead of an hostname works? |
Author Name: Alessandro Pasotti (@elpaso) I understand that this is just a workaround, but calling
initialize the system and then it works as expected, internally it dynamically load a bounch of system libraries (on unix). |
Author Name: Alessandro Pasotti (@elpaso) Lowering priority because we have a workaround.
|
Author Name: Giovanni Manghi (@gioman) Making it "high" as is a regression.
|
Author Name: Paolo Cavallini (@pcav) Could you please check again on current release? |
Author Name: Giovanni Manghi (@gioman) Paolo Cavallini wrote:
Please change status to "feedback" when needed.
|
Author Name: Nyall Dawson (@nyalldawson)
|
Author Name: David Marteau (@dmarteau)
Original Redmine Issue: 17866
Affected QGIS version: master
Redmine category:data_provider
When trying to load projects with wms or wcs layer defined from python: loading capabilities fail the first time with timeout error, thus preventing creating any project or layer from python.
The problem has been verified in Debian, Ubuntu and fresh OSX build from master branch.
The effect is that you cannot instanciate properly a QgsProject with a WMS layer.
This problem has been verified on Debian stretch, Ubuntu Xenial, OXS 10.11 from fresh master.
This can be tested by simply 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.
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:
Note that when you run this script, clear the Qgis network cache between two invocations.
On failure, the logs will show the following errors
After some investigation we have found that:
The text was updated successfully, but these errors were encountered: