首页 > 解决方案 > 切换后端数据库时打开 Airflow 网络服务器上的 password_auth.py 蘑菇云错误

问题描述

尝试从 sqlite db 过渡到 postgresql(基于此处的指南:https ://www.ryanmerlin.com/2019/07/apache-airflow-installation-on-ubuntu-18-04-18-10/ )并获得网络服务器 UI 的初始屏幕出现蘑菇云错误。

Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  ...
  ...
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/www/utils.py", line 93, in is_accessible
    (not current_user.is_anonymous and current_user.is_superuser())
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/contrib/auth/backends/password_auth.py", line 114, in is_superuser
    return hasattr(self, 'user') and self.user.is_superuser()
AttributeError: 'NoneType' object has no attribute 'is_superuser'

查看网络服务器日志并没有透露太多...

[airflow@airflowetl airflow]$ tail airflow-webserver.*
==> airflow-webserver.err <==
/home/airflow/.local/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)

==> airflow-webserver.log <==

==> airflow-webserver.out <==
[2019-12-18 10:20:36,553] {settings.py:213} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=72725

==> airflow-webserver.pid <==
72745

可能需要注意的一件事(因为这似乎是由于某种密码问题)是在尝试切换到 postgres 之前,我已经根据文档设置了 bycrpt 密码(https://airflow.apache.org /docs/stable/security.html#password)与此处的脚本:

import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser

user = PasswordUser(models.User())
user.username = 'airflow'
user.email = 'myemail@co.org'
user.password = 'mypasword'

session = settings.Session()
session.add(user)
session.commit()
session.close()
exit()

任何人都知道这里会发生什么或如何进一步调试?

标签: airflow

解决方案


重新运行我的用户/密码脚本解决了这个问题。

我假设这与以前使用的 sqllite db 对新 postgres 服务器的更改有关。我猜这存储在气流后端数据库中的某个位置(对气流来说相当新,所以不知道这些内部结构),并且由于我正在切换后端,新后端没有此用户/身份验证信息,需要重新运行脚本以导入气流包并将新用户/密码写入其后端,以便能够使用密码登录(因为我的airflow.cfg使用auth_backend = airflow.contrib.auth.backends.password_auth)。


推荐阅读