Skip to content

Instantly share code, notes, and snippets.

@ryandotclair
Last active November 27, 2015 20:08
Show Gist options
  • Save ryandotclair/404f2d4b7f05885d5b19 to your computer and use it in GitHub Desktop.
Save ryandotclair/404f2d4b7f05885d5b19 to your computer and use it in GitHub Desktop.
pg8000 connect
# Convert port to an int
db_port = int(db_port)
# Connect to the database
try:
db_connection = pg8000.connect(user=db_user, host=db_host,port=db_port,database=db_database,password=db_pass)
db_connection.autocommit = True
except Exception as e:
logger.critical(
'Unable to connect! Ensure $SRDBHOST, $SRDATABASE, $SRDBUSER and $SRDBPASS environmental variables are '
'properly set\n{0}'.format(e))
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment