[QGIS-Developer] QGIS standalone script examples (and Oracle)

Richard Duivenvoorde rdmailings at duif.net
Wed May 26 02:13:12 PDT 2021


On 5/26/21 9:19 AM, Paul Wittle wrote:

> The result is that the existing PostGIS layer is still broken but the second instance (the new layer added by the script) is working. Very curious; perhaps I need to put in a loop that scans the layer list looking for database layers and explicitly resets the data source.
> 
> I will also double check because the only other possibility may be that it is linked to the existing layers using the Authentication manager rather than a typed username and password in the project file.
> 
> Can anyone else replicate this issue or is it just me?

Hi Paul,

IF you use the authentication manager, is it possible that your script cannot find the authentication db (or does not provide a valid password/wallet to open it?)?
https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/authentication.html

I tested by adding a db layer in my 'template' project.
1 one with basic auth username/password
2 one using the authentication manager

Although I do not wreck my testoutput project (it still loads all layers after running test.py), I do see the following (I'm using a debug build of QGIS) running my test script:

../src/providers/postgres/qgspostgresconn.cpp:1063 : (postgisVersion) [250ms] geos:3.9.0-CAPI-1.16.2 proj:7.2.1
static bool LibSecretKeyring::findPassword(const QString&, const QString&, QKeychain::JobPrivate*)
../src/core/auth/qgsauthmanager.cpp:1005 : (configAuthMethod) [53ms] No config auth method found in database for authcfg: 7t8kl0t
../src/core/qgsdatasourceuri.cpp:526 : (connectionInfo) [0ms] Data source URI FAILED to update via loading configuration ID '7t8kl0t'
../src/core/qgsmessagelog.cpp:29 : (logMessage) [1ms] 2021-05-26T11:04:11 PostGIS[1] Connection to database failed
fe_sendauth: no password supplied

../src/core/vector/qgsvectorlayer.cpp:1565 : (readXml) [0ms] Could not set data provider for layer dbname='gis' host=localhost port=5432 sslmode=disable authcfg=7t8kl0t key='id' srid=28992 type=MultiPolygon checkPrimaryKeyUnicity='0' table="public"."prov" (geom)
../src/core/project/qgsproject.cpp:1233 : (addLayer) [0ms] Unable to load vector layer
../src/core/project/qgsproject.cpp:1578 : (readProjectFile) [39ms] Unable to get map layers from project file.
../src/core/project/qgsproject.cpp:1582 : (readProjectFile) [0ms] there are 1 broken layers
../src/core/qgsmessagelog.cpp:29 : (logMessage) [0ms] 2021-05-26T11:04:11 [1] 1 unavailable layers found:
../src/core/qgsmessagelog.cpp:29 : (logMessage) [0ms] 2021-05-26T11:04:11 [1]  * dbname='gis' host=localhost port=5432 sslmode=disable authcfg=7t8kl0t key='id' srid=28992 type=MultiPolygon checkPrimaryKeyUnicity='0' table="public"."prov" (geom)
../src/providers/postgres/qgspostgresconn.cpp:1063 : (postgisVersion) [62ms] geos:3.9.0-CAPI-1.16.2 proj:7.2.1

As said: my newly (written) project is still valid, are you overwriting the old qgs file?

Richard


More information about the QGIS-Developer mailing list