11
votes

I have a fresh install of windows where I am trying to install Postgres and pgAdmin4. I did a fresh install of everything (pgAdmin 4, postrgres 13, etc.) with default settings. When I run pgAdmin 4 I get a "fatal error: server could not be contacted" with the following message:

pgAdmin Runtime Environment
--------------------------------------------------------
Python Path: "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\python.exe"
Runtime Config File: "C:\Users\username\AppData\Roaming\pgadmin\runtime_config.json"
pgAdmin Config File: "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\config.py"
Webapp Path: "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py"
pgAdmin Command: "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\python.exe -s C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py"
Environment: 
  - ALLUSERSPROFILE: C:\ProgramData
  - APPDATA: C:\Users\username\AppData\Roaming
  - CHROME_CRASHPAD_PIPE_NAME: \\.\pipe\crashpad_4296_YJZESWNMDVNGRRUO
  - CHROME_RESTART: NW.js|Whoa! NW.js has crashed. Relaunch now?|LEFT_TO_RIGHT
  - CommonProgramFiles: C:\Program Files\Common Files
  - CommonProgramFiles(x86): C:\Program Files (x86)\Common Files
  - CommonProgramW6432: C:\Program Files\Common Files
  - COMPUTERNAME: pcname
  - ComSpec: C:\Windows\system32\cmd.exe
  - configsetroot: C:\Windows\ConfigSetRoot
  - DriverData: C:\Windows\System32\Drivers\DriverData
  - HOMEDRIVE: C:
  - HOMEPATH: \Users\username
  - LOCALAPPDATA: C:\Users\username\AppData\Local
  - LOGONSERVER: \\pcname
  - NUMBER_OF_PROCESSORS: 8
  - NVM_HOME: C:\Users\username\AppData\Roaming\nvm
  - NVM_SYMLINK: C:\Program Files\nodejs
  - OneDrive: C:\Users\username\OneDrive
  - OS: Windows_NT
  - Path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;C:\Program Files\PostgreSQL\12\bin;C:\Users\username\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Users\username\AppData\Local\Microsoft\WindowsApps;C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin
  - PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
  - PGADMIN_INT_KEY: 2e023387-9c82-4cdd-af2f-c82562c6e4fc
  - PGADMIN_INT_PORT: 50567
  - PGADMIN_SERVER_MODE: OFF
  - PROCESSOR_ARCHITECTURE: AMD64
  - PROCESSOR_IDENTIFIER: Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
  - PROCESSOR_LEVEL: 6
  - PROCESSOR_REVISION: 8c01
  - ProgramData: C:\ProgramData
  - ProgramFiles: C:\Program Files
  - ProgramFiles(x86): C:\Program Files (x86)
  - ProgramW6432: C:\Program Files
  - PSModulePath: C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
  - PUBLIC: C:\Users\Public
  - SystemDrive: C:
  - SystemRoot: C:\Windows
  - TEMP: C:\Users\username\AppData\Local\Temp
  - TMP: C:\Users\username\AppData\Local\Temp
  - USERDOMAIN: pcname
  - USERDOMAIN_ROAMINGPROFILE: pcname
  - USERNAME: username
  - USERPROFILE: C:\Users\username
  - windir: C:\Windows
--------------------------------------------------------

Traceback (most recent call last):
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py", line 98, in <module>
    app = create_app()
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\__init__.py", line 347, in create_app
    if not os.path.exists(SQLITE_PATH) or get_version() == -1:
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\setup\db_version.py", line 19, in get_version
    return version.value
AttributeError: 'NoneType' object has no attribute 'value'

Note: 'username' and 'pcname' are placeholders that I substituted for the actual strings, some of which were originally capitalized.

Verified service "postgresql-x64-13" was running. I continue to get this message despite trying the following:

  • Running as administrator.
  • Deleting C:\Users\username\AppData\Roaming\pgadmin.
  • Adding C:\Program Files\PostgreSQL\13\bin to the PATH environment variable (system and user)
  • Restarting the service.
  • Uninstalling/reinstalling Postgres 13.
  • Uninstalling/installing Postgres 12.
  • Restarting my machine.

The one thing that yielded different results was stopping the service, deleting C:\Users\username\AppData\Roaming\pgadmin, restarting the service, then running pg4admin which resulted in a "fatal error" with the following output:

pgAdmin Runtime Environment
--------------------------------------------------------
Python Path: "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\python.exe"
Runtime Config File: "C:\Users\username\AppData\Roaming\pgadmin\runtime_config.json"
pgAdmin Config File: "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\config.py"
Webapp Path: "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py"
pgAdmin Command: "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\python.exe -s C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py"
Environment: 
  - ALLUSERSPROFILE: C:\ProgramData
  - APPDATA: C:\Users\username\AppData\Roaming
  - CHROME_CRASHPAD_PIPE_NAME: \\.\pipe\crashpad_10312_CHCJAQAYYFQQIAGB
  - CHROME_RESTART: NW.js|Whoa! NW.js has crashed. Relaunch now?|LEFT_TO_RIGHT
  - CommonProgramFiles: C:\Program Files\Common Files
  - CommonProgramFiles(x86): C:\Program Files (x86)\Common Files
  - CommonProgramW6432: C:\Program Files\Common Files
  - COMPUTERNAME: pcname
  - ComSpec: C:\Windows\system32\cmd.exe
  - configsetroot: C:\Windows\ConfigSetRoot
  - DriverData: C:\Windows\System32\Drivers\DriverData
  - HOMEDRIVE: C:
  - HOMEPATH: \Users\username
  - LOCALAPPDATA: C:\Users\username\AppData\Local
  - LOGONSERVER: \\pcname
  - NUMBER_OF_PROCESSORS: 8
  - NVM_HOME: C:\Users\username\AppData\Roaming\nvm
  - NVM_SYMLINK: C:\Program Files\nodejs
  - OneDrive: C:\Users\username\OneDrive
  - OS: Windows_NT
  - Path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;C:\Program Files\PostgreSQL\13\bin;C:\Users\username\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Users\username\AppData\Local\Microsoft\WindowsApps;C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\username\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\PostgreSQL\13\bin;
  - PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
  - PGADMIN_INT_KEY: cb6cf8e1-ca8b-416b-985f-1fd1a945ff06
  - PGADMIN_INT_PORT: 50906
  - PGADMIN_SERVER_MODE: OFF
  - PROCESSOR_ARCHITECTURE: AMD64
  - PROCESSOR_IDENTIFIER: Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
  - PROCESSOR_LEVEL: 6
  - PROCESSOR_REVISION: 8c01
  - ProgramData: C:\ProgramData
  - ProgramFiles: C:\Program Files
  - ProgramFiles(x86): C:\Program Files (x86)
  - ProgramW6432: C:\Program Files
  - PSModulePath: C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
  - PUBLIC: C:\Users\Public
  - SESSIONNAME: Console
  - SystemDrive: C:
  - SystemRoot: C:\Windows
  - TEMP: C:\Users\username\AppData\Local\Temp
  - TMP: C:\Users\username\AppData\Local\Temp
  - USERDOMAIN: pcname
  - USERDOMAIN_ROAMINGPROFILE: pcname
  - USERNAME: username
  - USERPROFILE: C:\Users\username
  - windir: C:\Windows
--------------------------------------------------------

NOTE: Configuring authentication for DESKTOP mode.

Traceback (most recent call last):
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py", line 91, in <module>
    exec(open(file_quote(setup_py), 'r').read())
  File "<string>", line 506, in <module>
  File "<string>", line 378, in setup_db
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\__init__.py", line 351, in create_app
    db_upgrade(app)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\setup\db_upgrade.py", line 25, in db_upgrade
    flask_migrate.upgrade(migration_folder)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\flask_migrate\__init__.py", line 96, in wrapped
    f(*args, **kwargs)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\flask_migrate\__init__.py", line 271, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\alembic\command.py", line 294, in upgrade
    script.run_env()
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\alembic\script\base.py", line 490, in run_env
    util.load_python_file(self.dir, "env.py")
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\alembic\util\pyfiles.py", line 97, in load_python_file
    module = load_module_py(module_id, path)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\alembic\util\compat.py", line 182, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\setup\..\..\migrations\env.py", line 93, in <module>
    run_migrations_online()
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\setup\..\..\migrations\env.py", line 86, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\alembic\runtime\environment.py", line 813, in run_migrations
    self.get_context().run_migrations(**kw)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\alembic\runtime\migration.py", line 561, in run_migrations
    step.migration_fn(**kw)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\migrations\versions\fdc58d9bd449_.py", line 122, in upgrade
    Security(current_app, user_datastore, register_blueprint=False)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\flask_security\core.py", line 1062, in __init__
    self._state = self.init_app(
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\flask_security\core.py", line 1102, in init_app
    self._state = state = _get_state(app, datastore, **kwargs)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\flask_security\core.py", line 608, in _get_state
    remember_token_serializer=_get_serializer(app, "remember"),
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\flask_security\core.py", line 593, in _get_serializer
    return URLSafeTimedSerializer(secret_key=secret_key, salt=salt)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\itsdangerous\serializer.py", line 104, in __init__
    self.secret_keys: _t.List[bytes] = _make_keys_list(secret_key)
  File "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\lib\site-packages\itsdangerous\signer.py", line 64, in _make_keys_list
    return [want_bytes(s) for s in secret_key]
TypeError: 'NoneType' object is not iterable

I recently installed this on a different machine without any issues. Seems odd that a fresh build would have the issues. Almost makes me think I am lacking something the older build contains (python?), although this shouldn't be the case. There are lots of posts about this and I have tried everything suggested in them without resolution.

7
Im having the same error. Did you figured out?Delsx
I have not @Delsx. Hopefully someone can chime in.nonethewiser
I installed PgAdmin 4 V5 standalone, then I have delete Roaming/pgadmin, and opened pgadmin4 as admin.Delsx
Thanks so much for chiming in - I will give that a shot. I take it you downloaded the standalone installer from here? pgadmin.org/downloadnonethewiser
I was having the same issue today with a brand new postgresql install and none of the things you listed above in the question working. Installing the pgAdmin standalone and deleting the folder like @Delsx suggested worked (although I didn't have to run it as administrator). After running the standalone once, it appears that the pgAdmin that was installed with the postgresql installer now works too.Brandon

7 Answers

8
votes

As Delsx pointed out in the comments, the standalone pgAdmin can be installed without the same issues from pgadmin.org/download. It appears this is a widespread bug that has been reported on the pgAdmin bug list, here and here

3
votes

In the end the solution that work for me was:

  1. Delete C:\Users\username\AppData\Roaming\pgadmin
  2. Open the terminal and run C:\Program Files\PostgreSQL\12\pgAdmin 4\web\pgAdmin4.py file using python

Terminal view -> python execution

  1. Run as administrator the "pgAdmin 4" app from the windows menu and it will work as expected
1
votes

I had this issue as well. I followed the suggested answer from nonethewiser, installing the stand-alone pgAdmin. It didn't work after having deleted Roaming/pgadmin and starting as admin. I tried the bundled pgAdmin again and it works, strangely.

1
votes

The solution that work for me:

Download pgAdmin4 at: https://www.postgresql.org/ftp/pgadmin/pgadmin4/v5.2/windows/ Download Sql server at: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads When setting, uncheck install pgAdmin 4 and StackBuilder.

1
votes

I've been searching about this issue and I did the following

  1. Delete C:\Users\username\AppData\Roaming\pgadmin folder
  2. Add the next windows user enviroment variable

SQLITE_PATH = C:\Users\*YourUsername*\AppData\Roaming\pgadmin\pgadmin4.db

  1. Open cmd at C:\Program Files\pgAdmin 4\v5\web and run with python the setup.py file
  2. Install all missing dependencies if any
  3. Once setup.py finishes successfully you should delete pgadmin folder from AppData again
  4. Run setup.py one more time
  5. Open pgAdming4 normally (not as administrator)

This workaround works for me

My setup is PostgreSQL 9.6, pgAdmin4 v5.3 and Python 3.9.5

1
votes

This solution worked for me:

Remove pgAdmin4 only from your system (In Individual Component uninstall mode).

Then download and install pgAdmin4 at: https://www.postgresql.org/ftp/pgadmin/pgadmin4/v5.2/windows/

Delete C:\Users*YourUsername*\AppData\Roaming\pgadmin

Run PgAdmin4

0
votes

If even the standalone pgAdmin4 exe doesn't work, go to the python virtual enviroment (if you don't have any then install it using pip). Install the pgAdmin package in the virtual environment(pip install pgadmin4). Navigate to C:\Users(username)\Envs(or you respective env folder)\test( or your respective environment name)\Lib\site-packages\pgadmin4\pgAdmin4.py. Incase while running the py file you may run into cheroot module no fot found, then inside the virtual env install pip install cheroot and you're done. Remember to activate the evironment before doing this. Do this in two seperate cmd windows for convinience.

the above mentioned procedure is sure to work even if the exe is not working.

Also verify once that postgresql is listening in port: 5432 else change the port in postgresql.conf