Windows – The pgAdmin 4 server could not be contacted

pgadminpgadmin-4windows

I've installed PostgreSQL 12, and pgAdmin 4. When I try to run pgAdmin 4 i get a fatal error "The pgAdmin 4 server could not be contacted". I've tried running it as administrator, deleting files at "C:\Users\User\AppData\Roaming\pgAdmin" and adding "C:\Program Files\PostgreSQL\12\bin" to system environment variables. I don't know what else can I do. I'm sure that the PostgreSQL server is working since it's service at services.msc is running.

Here are logs from running pgAdmin4. I can see that something is wrong here, but I don't know how to fix this:

Traceback (most recent call last):
  File "C:/Program Files/pgAdmin 4/v4/web/pgAdmin4.py", line 217, in <module>
    main()
  File "C:/Program Files/pgAdmin 4/v4/web/pgAdmin4.py", line 199, in main
    app.run(
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib/site-packages\flask\app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib/site-packages\werkzeug\serving.py", line 1052, in run_simple
    inner()
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib/site-packages\werkzeug\serving.py", line 996, in inner
    srv = make_server(
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib/site-packages\werkzeug\serving.py", line 847, in make_server
    return ThreadedWSGIServer(
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib/site-packages\werkzeug\serving.py", line 740, in __init__
    HTTPServer.__init__(self, server_address, handler)
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib\http\server.py", line 140, in server_bind
    self.server_name = socket.getfqdn(host)
  File "C:/Program Files/pgAdmin 4/v4/venv/Lib\socket.py", line 756, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 5: invalid start byte

Here is another .log file:

2020-08-31 17:15:12: Checking for system tray...
2020-08-31 17:15:12: Starting pgAdmin4 server...
2020-08-31 17:15:12: Creating server object, port:52967, key:459b0c86-b99e-46f0-9070-55554b9621d3, logfile:C:/Users/user/AppData/Local/pgadmin4.d41d8cd98f00b204e9800998ecf8427e.log
2020-08-31 17:15:12: Python Path: C:/Program Files/pgAdmin 4/v4/venv/Lib/site-packages;C:/Program Files/pgAdmin 4/v4/venv/DLLs;C:/Program Files/pgAdmin 4/v4/venv/Lib
2020-08-31 17:15:12: Python Home: C:/Program Files/pgAdmin 4/v4/venv
2020-08-31 17:15:12: Initializing Python...
2020-08-31 17:15:12: Python initialized.
2020-08-31 17:15:12: Adding new additional path elements
2020-08-31 17:15:12: Redirecting stderr...
2020-08-31 17:15:12: stderr redirected successfully.
2020-08-31 17:15:12: Initializing server...
2020-08-31 17:15:12: Webapp Path: C:/Program Files/pgAdmin 4/v4/web/pgAdmin4.py
2020-08-31 17:15:12: Server initialized, starting server thread...
2020-08-31 17:15:12: Open the application code and run it.
2020-08-31 17:15:12: Set the port number, key and force SERVER_MODE off
2020-08-31 17:15:12: PyRun_SimpleFile launching application server...
2020-08-31 17:15:13: Application Server URL: http://127.0.0.1:52967/?key=459b0c86-b99e-46f0-9070-55554b9621d3
2020-08-31 17:15:13: The server should be up. Attempting to connect and get a response.
2020-08-31 17:15:21: Failed to launch the application server, server thread exiting.

If you know what could I do, please help me.

Best Answer

After dealing with this issue myself, with the exact same error and stacktrace as given, I finally found a solution.

The host name of my pc is what was causing the issue, as it included an 'æ' in it which is a non-ASCII character. So the host name, if used for pgadmin, can apparently only include ASCII characters.

The solution was to just change the host name to something without the 'æ' (æ -> ae, in my case). The host name is the actual name of the pc, found and edited under system properties (This PC then Properties).