在Windows上使用psycopg2时,我会收到不需要的调试消息

2024-09-28 05:20:04 发布

您现在位置:Python中文网/ 问答频道 /正文

每个学生。在

我已经从psycopg2-2.5.1.win32-py2.6-pg9.2.4包中安装了psycopg2-版本.exe在站点http://www.stickpeople.com/projects/python/win-psycopg/中找到。 我可以导入它并连接到数据库,但是当我在命令行上运行我的脚本(标准和Cygwin)时,会将不需要的消息打印到stderr。在

例如:

conn = psycopg2.connect(host="42.42.42.42", port=5432, database="myDB", user="myUser", password="********")
if conn is None:
    sys.exit("Connection failed")
print "Connection successful"

打印如下:

^{pr2}$

我无法关闭这些信息。我在Google上搜索,但没有找到任何相关的东西,我还尝试更改标准日志模块的配置,以防其中一些模块被使用,但仍然没有效果。在

有人知道如何阻止这些信息吗?在

提前谢谢!在


Tags: 模块版本com信息http标准站点www
2条回答

这些信息来自Postgres本身。第二个是DEBUG3 模块backend/access/transam/xact.c中的消息。我会看看 在您的postgresql.conf中记录设置。在

看起来这个构建是用PSYCOPG_DEBUG标志集生成的,在查看http://www.stickpeople.com/projects/python/win-psycopg/处的表之后,发布版本不应该是这样(注意最后一列Debug Build ( define PSYCOPG_DEBUG))。但是看起来您已经设置了PSYCOPG_DEBUG环境变量。如果是这种情况,那么取消设置它应该可以防止发出这些调试消息。在

从psycopg2.txt

Creating a debug build

In case of problems, Psycopg can be configured to emit detailed debug messages, which can be very useful for diagnostics and to report a bug. In order to create a debug package:

  • Download and unpack the Psycopg source package.

  • Edit the "setup.cfg" file adding the "PSYCOPG_DEBUG" flag to the "define" option.

  • Compile and install the package.

  • Set the "PSYCOPG_DEBUG" variable:

    $ export PSYCOPG_DEBUG=1

  • Run your program (making sure that the "psycopg2" package imported is the one you just compiled and not e.g. the system one): you will
    have a copious stream of informations printed on stdout.

相关问题 更多 >

    热门问题