Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku logs say "No module named 'urlparse'" when I use import urlparse

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!!

like image 897
okcapp Avatar asked Aug 05 '17 04:08

okcapp


1 Answers

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

like image 113
Vikash Singh Avatar answered Sep 27 '22 22:09

Vikash Singh