I'm having trouble using the following lines of code from https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python
import os
import psycopg2
import urlparse
urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
I'm using Python 3.6.2
In my Heroku logs I'm seeing:
ModuleNotFoundError: No module named 'urlparse'
Any help would be much appreciated!!
urlparse
has been moved to a new module in python 3
from urllib.parse import urlparse
Read more here: https://docs.python.org/3.0/library/urllib.parse.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With