kn007的个人博客
♥ You are here: Home > 软件与网络 > VPS > 解决CentOS 8下pypolicyd-spf出错

解决CentOS 8下pypolicyd-spf出错

by | 8 Comments


如题,最近给服务器搬新家时发现,邮件系统收信时,postfix回显了下面内容,并以内部错误拒绝了对方邮件(对方服务器将会自动按照规定时间重试发送)。

需要先声明一点的是,本文章内容Python环境建立在Python 3基础上;policyd-spf在系统包管理中不存在,在pip中包名为pypolicyd-spf。

policyd-spf[627530]: Traceback (most recent call last):
policyd-spf[627530]: File "/usr/local/bin/policyd-spf", line 809, in
policyd-spf[627530]: instance_dict, configData, peruser, peruserconfigData)
policyd-spf[627530]: File "/usr/local/bin/policyd-spf", line 525, in _spfcheck
policyd-spf[627530]: res = heloquery.check()
policyd-spf[627530]: File "/usr/local/lib/python3.6/site-packages/spf.py", line 595, in check
policyd-spf[627530]: spf = self.dns_spf(self.d)
policyd-spf[627530]: File "/usr/local/lib/python3.6/site-packages/spf.py", line 1164, in dns_spf
policyd-spf[627530]: a = [t for t in self.dns_txt(domain) if RE_SPF.match(t)]
policyd-spf[627530]: File "/usr/local/lib/python3.6/site-packages/spf.py", line 1214, in dns_txt
policyd-spf[627530]: dns_list = self.dns(domainname, rr,ignore_void=ignore_void)
policyd-spf[627530]: File "/usr/local/lib/python3.6/site-packages/spf.py, line 1358, in dns
policyd-spf[627530]: for k, v in DNSLookup(name, qtype, self.strict, timeout):
policyd-spf[627530]: File "/usr/local/lib/python3.6/site-packages/spf.py", line 131, in DNSLookup_dnspython
policyd-spf[627530]: answers = dns.resolver.query(name, qtype, lifetime=timeout)
policyd-spf[627530]: TypeError: query() got an unexpected keyword argument 'lifetime'
postfix/spawn[627529]: warning: command /usr/local/bin/policyd-spf exit status 1
postfix/smtpd[627523): warning: premature end-of-input on private/policyd-spf while reading input attribute name

通过policyd-spf本身代码及错误得知可能是依赖的python3-pyspf(pip包名为pyspf)出问题。

排查后,在pyspf快速开始的“安装”一章中,找到了原因。

虽然pyspf支持dnspython/Py3DNS,但实际用起来是优先使用了dnspython,而最新版本的pyspf需要本地dnspython版本至少是1.16.0及以上。

而在CentOS 8系统包管理中dnspython名为python3-dns,通过dnf检查,可知最新版本为1.15.0-10,不及pyspf最低要求。

所以我们只要通过如下命令更新dnspython即可解决该问题。

pip3 install --upgrade dnspython

当然你也可以卸载dnspython,通过系统包管理安装python3-py3dns包(pip包名为py3dns)来解决这个问题。但万一有其他依赖于dnspython的python脚本就傻眼了。

转载请注明转自:kn007的个人博客的《解决CentOS 8下pypolicyd-spf出错

donate
有所帮助?

Comments

8 Comments立即评论
  1. CentOS 7 来坐个沙发~ :razz:

    1. MOD回复

      @老杨: :arrow: 该升级了

  2. 回复

    更新至 dnspython 1.16

    1. MOD回复

      @更新小助手: :sad: 怎么老是你。
      看到站点活了

  3. 差点看错以为你把博客迁移用python了 :cry:

    1. MOD回复

      @World: :o 这。。。可还行

  4. 好久没来了。。~~

    1. MOD回复

      @郑永: 欢迎

icon_wink.gificon_neutral.gificon_mad.gificon_twisted.gificon_smile.gificon_eek.gificon_sad.gificon_rolleyes.gificon_razz.gificon_redface.gificon_surprised.gificon_mrgreen.gificon_lol.gificon_idea.gificon_biggrin.gificon_evil.gificon_cry.gificon_cool.gificon_arrow.gificon_confused.gificon_question.gificon_exclaim.gif