I've tried to add a postgis-vector-layer in qgis 2.14.0 by using authentication (authConfigId) and PyQGIS. When running the script I'm asked to login by username/password instead of using authConfigID. What is wrong with "uri.setConnection" ?
Example of the script:
uri.setConnection("host_name","5432","database_name", "4zoa91a" ) #"4zoa91a" = my_example_authConfigId uri.setDataSource("table_name","geometry_column_name","key_column_name") vLayer=QgsVectorLayer(uri.uri(),"layer_name", "postgres") if vLayer.isValid() : print('layer is valid' ) QgsMapLayerRegistry.instance().addMapLayers([vLayer])
In developer cookbook there is no hint to solve the problem. In the QGIS api-documentation I discovered:
void QgsDataSourceURI::setConnection ( const QString & aHost, const QString & aPort, const QString & aDatabase, const QString & aUsername, const QString & aPassword, SSLmode sslmode = SSLprefer, const QString & authConfigId = QString()
Here username/password are required, but as I said, I've tried to use the AuthentificationConfigID instead. (Is no problem to load this layer in qgis via interface.).
(Further it would be nice to get a hint/link how to "read"/"apply" the qgis-api-documentation/structure.)