Created
April 19, 2017 19:20
-
-
Save claraj/caa2478571da264279c51ce6818439fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import psycopg2 | |
from urllib.parse import urlparse | |
#https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python | |
p_url = urlparse(os.environ["DATABASE_URL"]) | |
url = urlparse(p_url) | |
conn = psycopg2.connect( | |
database=url.path[1:], | |
user=url.username, | |
password=url.password, | |
host=url.hostname, | |
port=url.port | |
) | |
print('Connected to postgres.') | |
# Todo do database stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment