连接到 postgres 中的 URI [英] Connect to an URI in postgres

查看:91
本文介绍了连接到 postgres 中的 URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜这是一个非常基本的问题,但我不知道为什么:

I'm guessing this is a pretty basic question, but I can't figure out why:

import psycopg2
psycopg2.connect("postgresql://postgres:postgres@localhost/postgres")

出现以下错误:

psycopg2.OperationalError: missing "=" after
"postgresql://postgres:postgres@localhost/postgres" in connection info string

有什么想法吗?根据有关连接字符串的文档,我相信它应该可以工作,但是它只是这样:

Any idea? According to the docs about connection strings I believe it should work, however it only does like this:

psycopg2.connect("host=localhost user=postgres password=postgres dbname=postgres")

我在 Ubuntu12.04 上的 Python2.7.3 上使用最新的 psycopg2 版本

I'm using the latest psycopg2 version on Python2.7.3 on Ubuntu12.04

推荐答案

传递给 psycopg2.connect 的连接字符串没有被 psycopg2 解析:它被逐字传递给libpq.PostgreSQL 9.2 中添加了对连接 URI 的支持.

The connection string passed to psycopg2.connect is not parsed by psycopg2: it is passed verbatim to libpq. Support for connection URIs was added in PostgreSQL 9.2.

这篇关于连接到 postgres 中的 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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