Skip to content

Commit

Permalink
Merge pull request #3635 from arnaud-morvan/processing_postgis_connect
Browse files Browse the repository at this point in the history
[processing][db_manager] Fix connection to postgis
  • Loading branch information
rouault committed Nov 13, 2016
2 parents dbf6107 + 9cd39e7 commit 8b1adc5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -64,7 +64,7 @@ def __init__(self, uri):

expandedConnInfo = self._connectionInfo()
try:
self.connection = psycopg2.connect(expandedConnInfo.encode('utf-8'))
self.connection = psycopg2.connect(expandedConnInfo)
except self.connection_error_types() as e:
err = str(e)
uri = self.uri()
Expand All @@ -83,7 +83,7 @@ def __init__(self, uri):

newExpandedConnInfo = uri.connectionInfo(True)
try:
self.connection = psycopg2.connect(newExpandedConnInfo.encode('utf-8'))
self.connection = psycopg2.connect(newExpandedConnInfo)
QgsCredentials.instance().put(conninfo, username, password)
except self.connection_error_types() as e:
if i == 2:
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -88,6 +88,9 @@ def connect(self, parent=None):

settings.endGroup()

if hasattr(authcfg, 'isNull') and authcfg.isNull():
authcfg = ''

if service:
uri.setConnection(service, database, username, password, sslmode, authcfg)
else:
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/tools/postgis.py
Expand Up @@ -59,6 +59,9 @@ def uri_from_name(conn_name):

settings.endGroup()

if hasattr(authcfg, 'isNull') and authcfg.isNull():
authcfg = ''

if service:
uri.setConnection(service, database, username, password, sslmode, authcfg)
else:
Expand Down Expand Up @@ -202,7 +205,7 @@ def __init__(self, host=None, port=None, dbname=None, user=None,
for i in range(4):
expandedConnInfo = self.uri.connectionInfo(True)
try:
self.con = psycopg2.connect(expandedConnInfo.encode('utf-8'))
self.con = psycopg2.connect(expandedConnInfo)
if err is not None:
QgsCredentials.instance().put(conninfo,
self.uri.username(),
Expand Down

0 comments on commit 8b1adc5

Please sign in to comment.