skip to Main Content

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:UsersandreAppDataLocalProgramsPythonPython310libsite-packagespsycopg2__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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Open Task Manager > Services tab > Right-Click on Mongo > Start.
    Now go re-run the server again.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search