Unable to connect to DB server with psycopg2

Asked 1 months ago, Updated 1 months ago, 5 views

Please let me know.The psycopg2 returns an error.
Source code is

#-*-coding:utf-8-*- 

import psycopg2

if__name__=="__main__":

    connector=psycopg2.connect(host="127.0.0.1", database="pdb", user="pgusr", port=532 , password="pgpsw")
    cursor=connector.cursor()

    sql = "insert into test_table values ('1', 'python')"
    cursor.execute(sql)
    sql = "insert into test_table values ('2', 'Pyson')"
    cursor.execute(sql)
    sql = "insert into test_table values ('3', 'pison')"
    cursor.execute(sql)

    connector.commit()

    cursor.close()
    connector.close()

In , the environment is python 2.7.11 on Windows.

What is the cause?Is it not possible to install only the Dalai Lama?
The error content is

Traceback (most recent call last): File "test105.py", line 7, in

connector=psycopg2.connect(host="127.0.0.1", database="pdb", user="pgusr", port=532 ,
password="pgpsw")File
"C:\Python27\lib\site-packages\psycopg2_init__.py", line 164, in
connect
conn=_connect(dsn, connection_factory=connection_factory, async=async) psycopg2.OperationalError: could not connect to server:
Connection refused (0x0000274D/10061)
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

python postgresql

2022-09-30 11:19

1 Answers

The connection to PostgreSQL has failed, so please set up your environment to connect to PostgreSQL.

  • Service is not started
  • PostgreSQL is not configured to accept network connections
  • Windows Firewall does not allow connections


2022-09-30 11:19

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.