Byg*_*yga 4 python passwords postgis qgis
我正在制作一个 QGIS 插件,在其中我为 PostgreSQL 连接(已在用户的连接列表中设置)请求身份验证对象(使用 QgsProcessingParameterAuthConfig)。我的目标是使用 PyQGIS 获取登录名和密码,并使用这些与 psycopg2 连接。
被询问的参数 QgsProcessingParameterAuthConfig 返回一个字符串,其中包含身份验证对象的标识密钥。
小智 7
因此,您似乎对字符串 (id) 执行以下操作:
# get the config id as a string
auth_method_id = self.parameterAsString(
parameters,
self.AUTH_CONFIG,
context
)
# get the application's authenticaion manager
auth_mgr = QgsApplication.authManager()
# create an empty authmethodconfig object
auth_cfg = QgsAuthMethodConfig()
# load config from manager to the new config instance and decrypt sensitive data
auth_mgr.loadAuthenticationConfig(auth_method_id, auth_cfg, True)
# get the configuration information (including username and password)
auth_cfg.configMap()
Run Code Online (Sandbox Code Playgroud)
我从文档的各个地方得到了这个:
https://qgis.org/pyqgis/master/core/QgsAuthManager.html
https://qgis.org/pyqgis/master/core/QgsAuthMethodConfig.html
https://qgis.org/pyqgis/master/core/QgsProcessingParameterAuthConfig.html
| 归档时间: |
|
| 查看次数: |
427 次 |
| 最近记录: |