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

Paul Wittle paul.wittle at dorsetcouncil.gov.uk
Tue Jun 1 07:12:04 PDT 2021


Hi,

After a short break I've started looking at this again now and I think I can confirm that I'm now able to update a project with PostGIS tables with no issue (i.e. they still work after the .write() command).

Unfortunately the same can not be said for the Oracle layers so I think there must be another path I need to set?

You mentioned you'd explicitly set the Oracle paths in something you did previously...is there an Oracle setting that should be set if running QGIS standalone?

Thanks again for all your help on this.
Paul

-----Original Message-----
From: Paul Wittle
Sent: 26 May 2021 11:58
To: rdmailings at duif.net
Cc: qgis-dev <Qgis-developer at lists.osgeo.org>
Subject: RE: [QGIS-Developer] QGIS standalone script examples (and Oracle)

Hi,

I think I've worked it out.

The initialisation of the authentication manager needs to be done before the project read command.

I had the logic near where I was adding a layer (i.e. after the opening of the project) but it needs to be initialised before the project is read. The result is that the original layers are now still valid.

I knew it would be obvious when I worked it out.

The only outstanding question is why the authenticationDatabasePath() Returns a path in the AppData\Roaming\python Folder instead of AppData\Roaming\QGIS despite my specifying the correct path in the .init() function?

Thank you again for all your help on this as I think I should be able to get it working now even if I do have to copy the relevant *.db files to the python folder.

Best Regards,
Paul

-----Original Message-----
From: Richard Duivenvoorde <rdmailings at duif.net>
Sent: 26 May 2021 10:13
To: Paul Wittle <paul.wittle at dorsetcouncil.gov.uk>
Cc: qgis-dev <Qgis-developer at lists.osgeo.org>
Subject: Re: [QGIS-Developer] QGIS standalone script examples (and Oracle)

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
This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly. Unless you are the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to recording and/or monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council does not accept service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from computer viruses, Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see www.dorsetcouncil.gov.uk/data-protection


More information about the QGIS-Developer mailing list