【问题标题】:Heroku logs say "No module named 'urlparse'" when I use import urlparse当我使用 import urlparse 时,Heroku 日志显示“没有名为 'urlparse' 的模块”
【发布时间】:2018-01-13 01:32:01
【问题描述】:

我在使用来自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”的模块

任何帮助将不胜感激!

【问题讨论】:

  • AWS Lambda 上的 Python 也将我带到了这里!

标签: python postgresql heroku flask


【解决方案1】:

urlparse 已移至 python 3 中的新模块

from urllib.parse import urlparse

在此处阅读更多信息:https://docs.python.org/3.0/library/urllib.parse.html

【讨论】:

  • 感谢您的回复!当我进行您建议的更改时,我收到了另一个错误。现在,在 Heroku 日志中,我看到:AttributeError: 'function' object has no attribute 'uses_netloc'
  • 这是您代码中的错误。您可以使用更新的代码和 heroku 错误日志跟踪发布不同的问题..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-13
  • 2013-01-02
  • 1970-01-01
  • 2016-05-04
  • 2011-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多