2

i am trying to fetch data from postgres in qgis and the connection code is working fine in python console but it gives error when i apply that code to my plugin like..

AttributeError: 'NoneType' object has no attribute 'connect'

and my code for connection is

import psycopg2

connection = psycopg2.connect(
    database="test",
    user="postgres",
    password="123",
    host="localhost",
    port=5432
    )

try:
    cursor = connection.cursor()
    check = '''SELECT * FROM testid WHERE "Property_ID" = '54' '''
    cursor.execute(check)
    a = cursor.fetchall()
    print a

except psycopg2.OperationalError:
    pass

Your Answer

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

Browse other questions tagged or ask your own question.