View Issue Details

IDProjectCategoryView StatusLast Update
0012393CentOS-7pythonpublic2017-11-21 14:39
Reporterdrencrom Assigned To 
Status newResolutionopen 
Product Version7.3.1611 
Summary0012393: pypolicyd-spf fails decoding ip addresses
DescriptionWhen the policy-spf restriction is enabled in postfix using pypolicyd-spf-1.3.2-1.el7 there is an error for every incoming email that says:

'<ip_address>' does not appear to be an IPv4 or IPv6 address. Did you pass in a bytes (str in Python 2) instead of a unicode object?. Aborting whitelist processing.

The incoming email fails and the client server retries later.
Steps To ReproduceConfigure the policy-spf restriction in postfix using pypolicyd-spf-1.3.2-1.el7
TagsNo tags attached.




2016-12-19 14:12

reporter   ~0028196

Just adding that this broke with the update of python-ipaddress to 1.0.16-2.el7


2016-12-31 17:31

reporter   ~0028254

Can confirm.

Dec 31 16:50:21 box policyd-spf[4336]: Traceback (most recent call last):
Dec 31 16:50:21 box policyd-spf[4336]: File "/usr/libexec/postfix/policyd-spf", line 700, in <module>
Dec 31 16:50:21 box policyd-spf[4336]: instance_dict, configData, peruser)
Dec 31 16:50:21 box policyd-spf[4336]: File "/usr/libexec/postfix/policyd-spf", line 412, in _spfcheck
Dec 31 16:50:21 box policyd-spf[4336]: res = spf.check2(ip, helo_fake_sender, helo, querytime=configData.get('Lookup_Time'))
Dec 31 16:50:21 box policyd-spf[4336]: File "/usr/lib/python2.7/site-packages/", line 297, in check2
Dec 31 16:50:21 box policyd-spf[4336]: receiver=receiver,timeout=timeout,verbose=verbose,querytime=querytime).check()
Dec 31 16:50:21 box policyd-spf[4336]: File "/usr/lib/python2.7/site-packages/", line 378, in __init__
Dec 31 16:50:21 box policyd-spf[4336]: self.set_ip(i)
Dec 31 16:50:21 box policyd-spf[4336]: File "/usr/lib/python2.7/site-packages/", line 405, in set_ip
Dec 31 16:50:21 box policyd-spf[4336]: self.ipaddr = ipaddress.ip_address(i)
Dec 31 16:50:21 box policyd-spf[4336]: File "/usr/lib/python2.7/site-packages/", line 163, in ip_address
Dec 31 16:50:21 box policyd-spf[4336]: ' a unicode object?' % address)
Dec 31 16:50:21 box policyd-spf[4336]: AddressValueError: '2607:f8b0:4002:c05::232' does not appear to be an IPv4 or IPv6 address. Did you pass in a bytes (str in Python 2) instead of a unicode object?


2017-02-18 01:15

reporter   ~0028599

Just for the record:
Corresponds to
Fixed in F22 a year ago.
Still broken in CentOS 7.


2017-02-22 11:37

reporter   ~0028636

For what it's worth I've added a COPR repo of the Perl equivalent that can be used as a substitute in the meantime.


2017-04-16 19:27

reporter   ~0029078

I believe this issue arrises when you have python-ipaddress installed. (I have it as a dependency for certbot)
I got around it by creating a python virtualenv and installing pypolicyd-spf inside (and not the python ipaddress module)

Here is my ansible shizzle:

- name: Packages
  yum: name={{ item }}
  - python-pip
  - python-virtualenv

- name: Install pypolicyd-spf with pip
    name: pypolicyd-spf
    virtualenv: /opt/pypolicyd-spf_env
    version: 1.3.2

- name: Install pypolicyd-spf dependencies
    name: "{{ item }}"
    virtualenv: /opt/pypolicyd-spf_env
    - ipaddr
    - pydns

And I have this in my

policyd-spf unix - n n - 0 spawn user=nobody
  argv=/opt/pypolicyd-spf_env/bin/python /opt/pypolicyd-spf_env/bin/policyd-spf


2017-07-07 14:10

reporter   ~0029623

my fix:
use python3

yum install python34
yum install python34-setuptools
easy_install-3.4 pip
pip3 install pyspf
pip3 install py3dns
pip3 install pypolicyd-spf

change python3 path in /etc/postfix/
policyd-spf unix - n n - 0 spawn user=nobody argv=/usr/bin/python3 /usr/libexec/postfix/policyd-spf

I hope this will help someone out there.


2017-09-24 08:32

reporter   ~0030190

I had this issue yesterday after installing Certbot (and thus the python-ipaddress dependency).

I had to disable SPF checking at first in Postfix.

However Vermeiremathias' solution above worked, installing Python3 alongside Python2.

Thank you!


2017-10-27 23:33

reporter   ~0030478

There is new version of this package - pypolicyd-spf-1.3.2-2.el7 in epel repo now with python-ipaddress package added as dependency! Could please someone confirm it's absolutely necessary? (I'm not capable of that) If not who should I write to to remove this nonsense? I don't like the idea of installing the whole new version of python just because of last digit version change. Thanks a lot.

 Package Arch Version Repository Size
 pypolicyd-spf noarch 1.3.2-2.el7 epel 44 k
Installing for dependencies:
 python-ipaddress noarch 1.0.16-2.el7 base 34 k

Transaction Summary
Install ( 1 Dependent package)
Upgrade 1 Package

Total download size: 79 k
Is this ok [y/d/N]:


2017-10-27 23:35

reporter   ~0030479

And yes, it breaks things just like before.


2017-10-30 16:20

reporter   ~0030486

After updating pypolicyd-spf as papundekl did, I dealt with this problem as follows.
However, the condition is that there are no dependent packages of python-ipaddress other than pypolicyd-spf.

 (1) rpm -e --nodeps python-ipaddress
 (2) vi /usr/libexec/postfix/policyd-spf
 (3) I change the following line (around line 40) as follows.
       - import ipaddress
       + import ipaddr as ipaddress.

I hope this will help.


2017-11-03 01:51

reporter   ~0030515

Check and test please:


2017-11-07 08:29

reporter   ~0030530

Yohei TOMIYAMA, works, thx!


2017-11-07 21:13

reporter   ~0030533

Thank you both Yohei for the workaround and Bojan ( for the fixed package.

Please test the fixed package referenced on , register and give positive karma. The package needs one more karma point to get it included in the stable repository.


2017-11-21 14:39

reporter   ~0030623

pypolicyd-spf-1.3.2-5.el7 and python-pyspf-2.0.11-5.el7 have made it to the stable repo 4 days ago as verified on:

This issue has been solved.

Issue History

Date Modified Username Field Change
2016-12-15 15:35 drencrom New Issue
2016-12-19 14:12 drencrom Note Added: 0028196
2016-12-31 17:31 techmsg Note Added: 0028254
2017-02-18 01:15 brad2014 Note Added: 0028599
2017-02-22 11:37 giesen Note Added: 0028636
2017-04-16 19:27 CoaxVex Note Added: 0029078
2017-07-07 14:10 vermeiremathias Note Added: 0029623
2017-09-24 08:32 MrCarrot Note Added: 0030190
2017-10-27 23:33 papundekl Note Added: 0030478
2017-10-27 23:35 papundekl Note Added: 0030479
2017-10-30 16:20 Yohei TOMIYAMA Note Added: 0030486
2017-11-03 01:51 papundekl Note Added: 0030515
2017-11-07 08:29 vanoc Note Added: 0030530
2017-11-07 21:13 rjmco Note Added: 0030533
2017-11-21 14:39 rjmco Note Added: 0030623