Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查
当使用rabbitmq作为airflow的broker的时候,启动scheduler,即执行airflow scheduler命令的时候抛出以下异常:
Traceback (most recent call last):
File "/anaconda/anaconda3/bin/airflow", line 27, in <module>
args.func(args)
File "/anaconda/anaconda3/lib/python3.6/site-packages/airflow/bin/cli.py", line 818, in scheduler
......
......
File "/anaconda/anaconda3/lib/python3.6/site-packages/kombu/connection.py", line 494, in _ensured
return fun(*args, **kwargs)
File "/anaconda/anaconda3/lib/python3.6/site-packages/kombu/messaging.py", line 203, in _publish
mandatory=mandatory, immediate=immediate,
File "/anaconda/anaconda3/lib/python3.6/site-packages/librabbitmq/__init__.py", line 122, in basic_publish
mandatory or False, immediate or False,
TypeError: an integer is required (got type NoneType)
整体环境描述:
python3.6 + apache-airflow1.9.0 + rabbitmq 3.6
因为使用redis作为broker是可以正常运行的,但是换成rabbitmq之后就出现了这种情况。尝试过对rabbitmq降版本,对airflow降低版本,发现依然无解,说明并不是软件版本兼容问题。
于是进一步排查,单独使用celery4.x进行调试,发现celery可以正常运行,但是到了airflow下就出现问题,说明是配置问题。
但是airflow的官方文档中配置是相当简陋的,而源码中相关的配置又相当的多,实在无法定位。于是采用最粗暴的做法,调试,但是服务器无法远程,没有外网端口,不能远程调试,而且airflow并不支持windows平台。于是只能通过日志调试:
首先,根据异常提示,说明有配置属性为空导致了这个异常,于是在异常处加上打印日志:
$ vi /anaconda/anaconda3/lib/python3.6/site-packages/librabbitmq/__init__.py
......
......
if isinstance(body, tuple):
body, properties = body
elif isinstance(body, self.Message):
body, properties = body.body, body.properties
print("---------------------------------------")
print(self.channel_id)
print("---------------------------------------")
print(body)
print("---------------------------------------")
print(exchange)
print("---------------------------------------")
print(routing_key)
print("---------------------------------------")
print(properties)
print("---------------------------------------")
print(mandatory)
print("---------------------------------------")
print(immediate)
print("---------------------------------------")
#if properties["priority"] is None: 加上这一句后就不会抛出异常了
# properties["priority"] = 0
return self.connection._basic_publish(
self.channel_id, body, exchange, routing_key, properties,
mandatory or False, immediate or False,
)
......
......
打印结果如下:
---------------------------------------
1
---------------------------------------
b'\x80\x02}q\x00(X\x04\x00\x00\x00taskq\x01X1\x00\x00\x00airflow.executors.celery_executor.execute_commandq\x02X\x02\x00\x00\x00idq\x03X$\x00\x00\x0077410b3a-75c6-4ba0-a448-7048c029e80cq\x04X\x04\x00\x00\x00argsq\x05]q\x06X\xcc\x00\x00\x00airflow run example_passing_params_via_test_command run_this 2018-07-02T01:04:00 --local -sd /anaconda/anaconda3/lib/python3.6/site-packages/airflow/example_dags/example_passing_params_via_test_command.pyq\x07aX\x06\x00\x00\x00kwargsq\x08}q\tX\x07\x00\x00\x00retriesq\nK\x00X\x03\x00\x00\x00etaq\x0bNX\x07\x00\x00\x00expiresq\x0cNX\x03\x00\x00\x00utcq\r\x88X\t\x00\x00\x00callbacksq\x0eNX\x08\x00\x00\x00errbacksq\x0fNX\t\x00\x00\x00timelimitq\x10NN\x86q\x11X\x07\x00\x00\x00tasksetq\x12NX\x05\x00\x00\x00chordq\x13Nu.'
---------------------------------------
default
---------------------------------------
celery
---------------------------------------
{'reply_to': 'd0552f0c-b341-30b6-9edb-fa9599715d6c', 'correlation_id': '77410b3a-75c6-4ba0-a448-7048c029e80c', 'delivery_mode': 2, 'content_type': 'application/x-python-serialize', 'content_encoding': 'binary', 'headers': {}, 'priority': None}
---------------------------------------
None
---------------------------------------
None
---------------------------------------
因为mandatory和immediate是bool类型,且都尝试过给其设置值,但是依然报错,最后还为None的就剩下priority属性为None了。于是尝试在代码中对其设置一个int类型的值,结果再次运行并无异常,说明缺少优先级属性导致了这个问题, 于是可以在priority属性为None的时候给它一个默认值:
......
......
if isinstance(body, tuple):
body, properties = body
elif isinstance(body, self.Message):
body, properties = body.body, body.properties
if properties["priority"] is None: #加上这一句后就不会抛出异常了
properties["priority"] = 0
return self.connection._basic_publish(
self.channel_id, body, exchange, routing_key, properties,
mandatory or False, immediate or False,
)
......
......
后续发现这样修改源码确实不会出现之前的问题,但是会出现
TypeError can't pickle memoryview objects
之类的异常,后确认是librabbitmq 2.0.0 + celery 4.x的兼容性问题,于是选择使用pyamqp协议而不是使用默认的amqp协议,具体操作就是将broker_url改为如下格式:
broker_url = pyamqp://cord:123456@10.55.63.51:5672//
### transport://userid:password@hostname:port/virtual_host
而将celery_result_backend改为其他实现,比如mysql:
celery_result_backend = db+mysql://af:123456@10.55.63.51/airflow
至此问题解决。
总结:
在排查问题的时候需要针对问题深入排查,而不是无根据的臆测,要针对提示去逐步排查,而不是一味无目的去尝试。
虽然该问题已解决,但是推测应该是缺失相关配置导致了这个问题,但是我加上了优先级相关的配置并不起作用,所以暂时通过修改源码修复这个问题。
Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查的更多相关文章
- Pycharm:设置完Anaconda后报错TypeError: an integer is required (got type bytes)
背景:安装了最新版本的Anaconda3.9后,在Pycharm中设置Python Interpreter为这个最新版本Anaconda文件下的python.exe后,控制台无法启动并报错TypeEr ...
- python使用open经常报错:TypeError: an integer is required的解决方案
错误是由于从os模块引入了所有的函数导致的,os模块下有一个open函数,接受整型的文件描述符和打开模式,from os import *引入os模块的open函数,覆盖了python内建的open函 ...
- 【Selenium+Python Webdriver】报错之:TypeError: user_login() missing 1 required positional argument: 'self'
先贴一下源码: base.py文件如下: from selenium import webdriver class Page(object): ''' 页面基础类,用于所有页面的继承 ''' rb_u ...
- python3.5安装pyHook,解决【TypeError: MouseSwitch() missing 8 required positional arguments: 'msg', 'x', 'y', 'data', 'time', 'hwnd', and 'window_name'】这个错误!
为什么安装 pyHook包:为Windows中的全局鼠标和键盘事件提供回调. Python应用程序为用户输入事件注册事件处理程序,例如鼠标左键,鼠标左键,键盘键等 先要实时获取系统的鼠标位置或者键盘输 ...
- TypeError: Fetch argument 0 has invalid type <type 'int'>, must be a string or Tensor. (Can not convert a int into a Tensor or Operation.)
6月5日的時候,修改dilated_seg.py(使用tensorflow)出現了報錯: TypeError: Fetch argument 0 has invalid type <type ' ...
- Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __ini ...
- TypeError: Fetch argument None has invalid type <type 'NoneType'>
(fetch, type(fetch)))TypeError: Fetch argument None has invalid type <type 'NoneType'> 我的解决方案是 ...
- TypeError: only integer scalar arrays can be converted to a scalar index
TypeError: only integer scalar arrays can be converted to a scalar index 觉得有用的话,欢迎一起讨论相互学习~Follow Me ...
- Django问题 TypeError: __init__() missing 1 required positional argument: 'on_delete'
问题:在执行python manage.py makemigrations learning_logs时,系统会报错,提示:TypeError: __init__() missing 1 requir ...
随机推荐
- RabbitMQ的基本介绍及与Spring整合
一,场景回顾 最近做电商购物项目,在分布式中搜索服务,商品详情服务都是独立的模块.那么有一个问题就是: 商品的原始数据保存在数据库中,增删改查都在数据库中完成. 搜索服务数据来源是索引库,如果数据 ...
- 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)
题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...
- net core Webapi基础工程搭建(四)——日志功能log4net
目录 前言 log4net 依然是,NuGet引用第三方类库 整合LogUtil 小结 前言 一个完整的项目工程离不开日志文件的记录,而记录文件的方法也有很多,可以自己通过Stream去实现文件的读写 ...
- DNS主、从域名服务器配置
#命令为红色 #vi编辑内容为蓝色 建立主.从或者缓存域名服务器,前提一定要关闭防火墙和linux防护机制,否则不能成功解析客户机请求 永久关闭防火墙和安全机制命令如下: systemctl stop ...
- 单元测试之NUnit一
NUnit 分三篇文章介绍,入门者可阅读文章,有基础者直接参考官方文档.初次写博客,望大家指点. 导航: 单元测试之NUnit一 单元测试之NUnit二 单元测试之NUnit三 NUnit是什么? N ...
- Redis学习总结(六)--Redis集群伸缩
我们在上一章讲了如何创建集群,今天我们来实现下集群的伸缩. 添加节点 操作流程 1.启动节点 2.将节点加入到集群中 3.将数据槽从原来的节点迁移部分到新节点上 实践 1)准备两个新节点并启动 [ro ...
- 使用jQuery.extend创建一个简单的选项卡插件
选项卡样式如图,请忽略丑陋的样式,样式可以随意更改 主要是基于jquery的extend扩展出的一个简单的选项卡插件,注意:这里封装的类使用的是es6中的class,所以不兼容ie8等低版本浏览器呦! ...
- [Python] 数据结构--实现顺序表、链表、栈和队列
说明: 本文主要展示Python实现的几种常用数据结构:顺序表.链表.栈和队列. 附有实现代码. 来源主要参考网络文章. 一.顺序表 1.顺序表的结构 一个顺序表的完整信息包括两部分,一部分是表中元素 ...
- Linux之Shell编程(14)
变量: 定义变量的规则: 1)变量名可以由字母.数字和下划线组成,但不能以数字开头 2)等号两侧不能有空格 3)变量名一般习惯大写 将命令的返回值赋值给变量: 1)使用``将命令括起来 2)使用$() ...
- Delphi - 通过WinAPI WinExec直接调用系统工具
看如下代码: WinExec('mspaint.exe', SW_SHOWNORMAL); // SW_SHOWNORMAL = 1 系统画图 WinExec('write.exe', SW_SHOW ...