我在使用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
)我使用的是Python 3.6.2
在我的Heroku日志中我看到:
ModuleNotFoundError:没有名为“urlparse”的模块
任何帮助都将不胜感激!
发布于 2017-08-05 12:57:32
urlparse已经移到了python3中的一个新模块。
from urllib.parse import urlparse点击此处阅读更多信息:https://docs.python.org/3.0/library/urllib.parse.html
https://stackoverflow.com/questions/45518179
复制相似问题