2

I try to read username and password from the qgis-auth.db, the latter having been configured under QGIS (3.6.1, Ubuntu).

Here is my code :

import os
import sys
from qgis.core import QgsApplication

argvb = list(map(os.fsencode, sys.argv))
qgisapp = QgsApplication(argvb, True)
qgisapp.initQgis()

authM = qgisapp.authManager()
authM.setMasterPassword("myMasterPassword", True)  # returns True
print(authM.authenticationDatabasePath())
# returns '/home/me/.local/share/profiles/default/qgis-auth.db'

it's not the QGIS3 default profile location, which is :

/home/me/.local/share/QGIS/QGIS3/profiles/default/qgis-auth.db

I'd like to avoid copying the auth database and read it directly from the default profile.

2

I missed the profileFolder argument in QgsApplication, found in the C++ code :

QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder, const QString &platformName )

I adapt my code and it works :

import os
import sys
from qgis.core import QgsApplication

argvb = list(map(os.fsencode, sys.argv))
qgisapp = QgsApplication(argvb, True, "/home/me/.local/share/QGIS/QGIS3/profiles/default", "desktop")

qgisapp.initQgis()

authM = qgisapp.authManager()
authM.setMasterPassword("myMasterPassword", True)  # returns True
print(authM.authenticationDatabasePath())
# returns '/home/me/.local/share/QGIS/QGIS3/profiles/default/qgis-auth.db'

print(authM.availableAuthMethodConfigs())
# returns {'dbconfid': <qgis._core.QgsAuthMethodConfig object at 0x____________>}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.