diff --git a/SPF2IP.py b/SPF2IP.py
index e6210f3..b95903e 100644
--- a/SPF2IP.py
+++ b/SPF2IP.py
@@ -29,14 +29,22 @@ def dns_request_unicode(hostname,record_type,*args,**kwargs):
         value = value.decode('utf-8')
       output.append(value)
     elif record_type == "MX":
-      value = entry.exchange
-      if type(value) is not unicode:
-        value = value.__str__().encode('utf-8').decode('utf-8')
+      try:
+        value = entry.exchange.decode('utf-8')
+      except AttributeError as err:
+        if err.args[0] == "'Name' object has no attribute 'decode'":
+          value = unicode(entry.exchange)
+        else:
+          raise
       output.append(value)
     elif record_type == "TXT":
-      value = ''.join([str(ent) for ent in entry.strings])
-      if type(value) is not unicode:
-        value = value.decode('utf-8')
+      value_array = []
+      for ent in entry.strings:
+        if type(ent) is not unicode:
+          value_array.append(ent.decode('utf-8'))
+        else:
+          value_array.append(ent)
+      value = ''.join(value_array)
       output.append(value)
   return output
 
diff --git a/setup.py b/setup.py
index 3b958d6..3561be0 100755
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
 
 setup(
     name='SPF2IP',
-    version='1.0.4',
+    version='1.0.5',
 
     description='Python module to get IP addresses from an SPF record',
     long_description=long_description,

Broken on 3.6
The current code always returns an empty answer on Python 3.6. This fixes it for me:

```
diff --git a/SPF2IP.py b/SPF2IP.py
index e6210f3..84683ff 100644
--- a/SPF2IP.py
+++ b/SPF2IP.py
@@ -34,7 +34,7 @@ def dns_request_unicode(hostname,record_type,*args,**kwargs):
         value = value.__str__().encode('utf-8').decode('utf-8')
       output.append(value)
     elif record_type == "TXT":
-      value = ''.join([str(ent) for ent in entry.strings])
+      value = ''.join([str(ent, encoding='ascii') for ent in entry.strings])
       if type(value) is not unicode:
         value = value.decode('utf-8')
       output.append(value)
```
I only know python3 so I can't give good advice on making code that works on both 2 and 3. But a friend of mine's package has this function that you might find useful:

```
def to_native_str(value, encoding='utf-8'):
    if isinstance(value, str):
        return value

    if six.PY3 and isinstance(value, six.binary_type):  #pragma: no cover                                                                                      
        return value.decode(encoding)
    elif six.PY2 and isinstance(value, six.text_type):  #pragma: no cover                                                                                      
        return value.encode(encoding)
```


diff --git a/test_SPF2IP.py b/test_SPF2IP.py
index 54caff5..6e88918 100644
--- a/test_SPF2IP.py
+++ b/test_SPF2IP.py
@@ -125,11 +125,13 @@ dns_records = {
 class fakedns:
   def __init__(self,value,record_type):
     if record_type == 'TXT':
-      self.strings = value
+      self.strings = []
+      for entry in value:
+        self.strings.append(entry.encode('utf-8'))
     elif record_type == 'A' or record_type == 'AAAA':
-      self.address = value
+      self.address = value.encode('utf-8')
     elif record_type == 'MX':
-      self.exchange = value
+      self.exchange = value.encode('utf-8')
 def fake_dns_resolver(hostname,record_type):
   try:
     dns_records[hostname]

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.9
requirements-test.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
dnspython==2.7.0
exceptiongroup==1.2.2
iniconfig==2.1.0
ipaddress==1.0.23
mock==5.2.0
nose==1.3.7
packaging==24.2
pluggy==1.5.0
pytest==8.3.5
-e git+https://github.com/nathandines/SPF2IP.git@7e3593a6f322c39a02c1c0f4a108b046ec6c1a20#egg=SPF2IP
tomli==2.2.1

name: SPF2IP
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - dnspython==2.7.0
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - ipaddress==1.0.23
      - mock==5.2.0
      - nose==1.3.7
      - packaging==24.2
      - pluggy==1.5.0
      - pytest==8.3.5
      - tomli==2.2.1
prefix: /opt/conda/envs/SPF2IP

test_SPF2IP.py::SPF2IPTestCases::test_included_list_is_string_list test_SPF2IP.py::SPF2IPTestCases::test_included_loop test_SPF2IP.py::SPF2IPTestCases::test_ip4_results test_SPF2IP.py::SPF2IPTestCases::test_ip6_results test_SPF2IP.py::SPF2IPTestCases::test_single_domain_ip4 test_SPF2IP.py::SPF2IPTestCases::test_single_domain_ip6 test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_a test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_a_external test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_a_external_slash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_a_slash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_aaaa test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_aaaa_external test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_aaaa_external_slash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_aaaa_slash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_a test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_a_external test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_a_external_slash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_a_slash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_aaaa test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_aaaa_external test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_aaaa_external_longslash test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_aaaa_slash test_SPF2IP.py::SPF2IPTestCases::test_spf_list_is_string_list_with_prefix test_SPF2IP.py::SPF2IPTestCases::test_spf_list_split_spf
test_SPF2IP.py::SPF2IPTestCases::test_dns_query_method_output test_SPF2IP.py::SPF2IPTestCases::test_domain_without_spf_results test_SPF2IP.py::SPF2IPTestCases::test_included_invalid_spf test_SPF2IP.py::SPF2IPTestCases::test_included_without_includes test_SPF2IP.py::SPF2IPTestCases::test_included_without_spf test_SPF2IP.py::SPF2IPTestCases::test_nonexistent_domain_results test_SPF2IP.py::SPF2IPTestCases::test_single_domain_empty test_SPF2IP.py::SPF2IPTestCases::test_single_domain_with_mx_a_external_longslash test_SPF2IP.py::SPF2IPTestCases::test_spf_list_invalid_spf test_SPF2IP.py::SPF2IPTestCases::test_spf_list_without_spf
setup.py SPF2IP.py
setup.py SPF2IP.py