![]() |
import psycopg2 issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: import psycopg2 issue (/thread-14966.html) |
import psycopg2 issue - bhuvneshdogra - Dec-27-2018 #!/usr/bin/python import psycopg2 from config import config def connect(): """ Connect to the PostgreSQL database server """ conn = None try: # read connection parameters params = config() # connect to the PostgreSQL server print('Connecting to the PostgreSQL database...') conn = psycopg2.connect(**params) # create a cursor cur = conn.cursor() # execute a statement print('PostgreSQL database version:') cur.execute('SELECT version()') # display the PostgreSQL database server version db_version = cur.fetchone() print(db_version) # close the communication with the PostgreSQL cur.close() except (Exception, psycopg2.DatabaseError) as error: print(error) finally: if conn is not None: conn.close() print('Database connection closed.') if __name__ == '__main__': connect()while executing above py script I am facing below issue Quote:MacBook-Pro-4:python_study bkumar$ ./check_connect.py RE: import psycopg2 issue - Larz60+ - Dec-27-2018 line 3 does not start on column 0, thus perceived as indented. If you fix this, and still get an error, it's indicative of package not not being installed, install with: pip install psycopg2Note: when posting error traceback, always post entire unmodified error message (in error tags). |