从 pgadmin4 创建数据库时出错

Error when create database from pgadmin4

当我从 pgadmin 4 创建数据库时,它总是显示错误弹出窗口:保存属性时出错。

我的电脑信息:

我在 pgadmin4.log 中的错误:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 180, in run_wsgi
    execute(self.server.app)
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 168, in execute
    application_iter = app(environ, start_response)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python3/dist-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/share/pgadmin4/web/pgadmin/browser/utils.py", line 242, in dispatch_request
    return method(*args, **kwargs)
  File "/usr/share/pgadmin4/web/pgadmin/browser/server_groups/servers/databases/__init__.py", line 157, in wrapped
    return f(self, *args, **kwargs)
  File "/usr/share/pgadmin4/web/pgadmin/browser/server_groups/servers/databases/__init__.py", line 489, in create
    data=data, conn=self.conn
  File "/usr/lib/python3/dist-packages/flask/templating.py", line 128, in render_template
    context, ctx.app)
  File "/usr/lib/python3/dist-packages/flask/templating.py", line 110, in _render
    rv = template.render(context)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/usr/share/pgadmin4/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/default/create.sql", line 10, in top-level template code
    ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
  File "/usr/share/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py", line 2079, in qtLiteral
    adapted.encoding = 'utf8'
AttributeError: attribute 'encoding' of 'psycopg2.extensions.QuotedString' objects is not writable

可能您需要 psycopg > 2.6.2。参见 https://github.com/psycopg/psycopg2/issues/331

注释掉 python 代码中的两行可解决问题:

sudo sed -i '2078,2079 s/^[^#]/#/' 
/usr/share/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py

行是:

   if hasattr(adapted, 'encoding'):
       adapted.encoding = 'utf8'

安装 python-psycopg2 补充,在 ubuntu:

sudo apt-get install python-psycopg2

这对我有用!

此致!