Home > Blockchain >  Postgresql cannot connect to server
Postgresql cannot connect to server

Time:12-22

The project is a django web app, packed on docker containers. For some reason, I cannot run the server and launch it.

when I run "manage.py runserver", this error occurs:

File "C:\Users\andre\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg2\__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "158.160.17.21", port 5432 failed: Connection refused (0x0000274D/10061)
        Is the server running on that host and accepting TCP/IP connections?

What do you think can be done with it? Thank you.

CodePudding user response:

The first line of your error tells me that you're using a locally installed copy of psycopg2, a Python client library for PostgreSQL, to connect to the database. This is happening behind the scenes when Django needs to make that connection, but it's interesting that it's installed locally, rather than in a docker container, given you said your Django webapp is running in Docker.

The third line of your error is very simple: it tells you that

  1. the programme is expecting Postgres to be served on a machine with the IP address 158.160.17.21 on port 5432 (the default port for Postgres)
  2. it isn't there

Now, this IP address is not a default and doesn't refer to your own machine, so it must be something you've provided. An IP lookup suggests it's in Venezuela (does that sound right to you?). Perhaps you are expecting Postgres to be served on a third party machine; if so, you'll need to check that you have the right IP address and that Postgres is being served there.

Otherwise, you'll need to reconfigure Django to seek Postgres elsewhere.

CodePudding user response:

Open Task Manager > Services tab > Right-Click on Mongo > Start. Now go re-run the server again.

  • Related