4

pgadmin4 is running perfectly before the system update of ubuntu 16.04 I didn't actually check what are those updates.

But after the update and I tried running pgAdmin, it boots up and shows the pgAdmin loading screen. Then it loads for a long while and eventually gives me the error:

The application server could not be contacted.

I checked the pgAdmin4 logs and it gives me:

AttributeError: 'Request' object has no attribute 'is_json'
2020-05-18 16:08:46,684: ERROR  pgadmin:  'Request' object has no attribute 'is_json'
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1473, in full_dispatch_request
    rv = self.preprocess_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1666, in preprocess_request
    rv = func()
  File "/usr/lib/python3/dist-packages/flask_principal.py", line 477, in _on_before_request
    identity = loader()
  File "/usr/lib/python3/dist-packages/flask_security/core.py", line 515, in _identity_loader
    if not isinstance(current_user._get_current_object(), AnonymousUserMixin):
  File "/usr/lib/python3/dist-packages/werkzeug/local.py", line 307, in _get_current_object
    return self.__local()
  File "/usr/lib/python3/dist-packages/flask_login/utils.py", line 26, in <lambda>
    current_user = LocalProxy(lambda: _get_user())
  File "/usr/lib/python3/dist-packages/flask_login/utils.py", line 302, in _get_user
    current_app.login_manager._load_user()
  File "/usr/lib/python3/dist-packages/flask_login/login_manager.py", line 313, in _load_user
    return self._load_from_request(request)
  File "/usr/lib/python3/dist-packages/flask_login/login_manager.py", line 370, in _load_from_request
    user = self.request_callback(request)
  File "/usr/lib/python3/dist-packages/flask_security/core.py", line 475, in _request_loader
    if request.is_json:
  File "/usr/lib/python3/dist-packages/werkzeug/local.py", line 348, in __getattr__
    return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'is_json'

I already tried searching for it, but I am not a python guy. My guess is python version incompatibility. I saw a previous question about this 4 days ago. And it was deleted. I am not sure why.

Note: There is no config changes or anything.

EDIT (thanks to @Des Magner comment): This bug is already being tracked by PostgreSQL team https://redmine.postgresql.org/issues/5565

2 Answers2

0

Got the same problem.

My solution is not the best and easiest but it works.

I create new virtual env with python 3.8 and try to run PgAdmin. Ofcourse it failures because of unavailable python modules. So I install module and run PgAdmin from terminal (like this "python3 /usr/share/pgadmin4/web/pgAdmin4.py") again then again and again...

Until I face the problem with import ImportError: cannot import name 'default_render_json' from 'flask_security.views'

The solution is here and it is pretty simple https://forums.opensuse.org/showthread.php/539523-pgAdmin4-startet-nicht-mehr?s=75392d29ead60bd332ff6f2541467dba&p=2930160#post2930160

Also you have to install libpq to compile psycopg2

In summary my steps are:

  1. sudo apt install libpq-dev
  2. activate virtual env with python 3.8
  3. pip install -r pip_freeze_output_file.txt
  4. fix ImportError: cannot import name 'default_render_json'

pip freeze output is:

alembic==1.4.2
astroid==2.3.3
Babel==2.8.0
backcall==0.1.0
bcrypt==3.1.7
blinker==1.4
Brotli==1.0.7
cffi==1.14.0
click==7.1.2
cryptography==2.9.2
decorator==4.4.2
dnspython==1.16.0
email-validator==1.1.1
entrypoints==0.3
Flask==1.1.2
Flask-BabelEx==0.9.4
Flask-Compress==1.5.0
Flask-Gravatar==0.5.0
Flask-Login==0.5.0
Flask-Mail==0.9.1
Flask-Migrate==2.5.3
Flask-Paranoid==0.2.0
Flask-Principal==0.4.0
Flask-Security==3.0.0
Flask-SQLAlchemy==2.4.1
Flask-WTF==0.14.3
future==0.18.2
idna==2.9
ipython==7.13.0
ipython-genutils==0.2.0
isort==4.3.21
itsdangerous==1.1.0
jedi==0.16.0
Jinja2==2.11.2
lazy-object-proxy==1.4.3
ldap3==2.7
Mako==1.1.2
MarkupSafe==1.1.1
mccabe==0.6.1
paramiko==2.7.1
parso==0.6.2
passlib==1.7.2
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.5
psutil==5.7.0
psycopg2==2.8.5
ptyprocess==0.6.0
pyasn1==0.4.8
pycodestyle==2.5.0
pycparser==2.20
pyflakes==2.1.1
Pygments==2.6.1
pylint==2.4.4
PyNaCl==1.3.0
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2020.1
simplejson==3.17.0
six==1.14.0
speaklater==1.3
SQLAlchemy==1.3.17
sqlparse==0.3.1
sshtunnel==0.1.5
traitlets==4.3.3
urllib3==1.25.8
wcwidth==0.1.9
Werkzeug==1.0.1
wrapt==1.11.2
WTForms==2.3.1
0

Install the latest pgAdmin4 version (4.22) using their python-wheel installer (Requires python 3.4+) as workaround while they fix this bug.

I used miniconda for creating a virtual environment in python 3.7.

Once I created and activated the virtual environment I:

  1. Created the folders "/var/lib/pgadmin" and "/var/log/pgadmin" and set up proper writing permissions for the user running the web server (apache or the user launching the "desktop" version).

  2. Make sure pip is installed in your environment:

    conda pip install
    
  3. Downloaded the latest wheel file and installed it using pip:

    pip install ./pgadmin4-4.22-py2.py3-none-any.whl
    
  4. Upgraded pyasn1 to version 0.4.8:

    pip install pyasn1==0.4.8
    

    and for upgrading to the latest version:

    pip install --upgrade pyasn1
    
  5. Ran the following command and followed the instructions to set up the admin account for pgAdmin4 web server:

    pgAdmin4
    

    or

    pgadmin4
    

For starting pgAdmin4 each time, you have to activate your conda environment first and then run the command "pgAdmin4" or "pgadmin4".

If you need the WSGI configuration file, you can find it at [/miniconda/installation/path]/lib/python3.X/site-packages/pgadmin4/ or at [/miniconda/installation/path]/envs/[your_virtualenv_name]/lib/python3.X/site-packages/pgadmin4/.

To deploy a WSGI server for pgAdmin4 please check this document.

Finally, if you want to use different paths to "/var/lib/pgadmin" and "/var/log/pgadmin":

  1. Create a config_local.py file alongside the existing config.py file. You can find it at the same directory where the WSGI configuration file is.

  2. Edit config_local.py and add the following settings. In most cases, the default file locations should be appropriate:

    LOG_FILE = '/var/log/pgadmin/pgadmin.log'
    SQLITE_PATH = '/var/lib/pgadmin/pgadmin.db'
    SESSION_DB_PATH = '/var/lib/pgadmin/sessions'
    STORAGE_DIR = '/var/lib/pgadmin/storage'