Heroku日志说“No module named'urlparse'”当我使用导入urlparse [英] Heroku logs say "No module named 'urlparse'" when I use import urlparse

查看:1004
本文介绍了Heroku日志说“No module named'urlparse'”当我使用导入urlparse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 https中的以下代码行://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python

  import os 
import psycopg2
import urlparse
$ b 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:No模块名为urlparse

任何帮助将不胜感激!!

解决方案

urlparse 已经被移动到python 3的新模块中了。

<$ p $来自urllib.parse的导入urlparse

阅读更多: https://docs.python.org/3.0/library/urllib.parse.html a>


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

这篇关于Heroku日志说“No module named'urlparse'”当我使用导入urlparse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆