Skip to content

Commit

Permalink
Merge pull request #525 from egbertbouman/fix_interface
Browse files Browse the repository at this point in the history
Ensure _get_interface_addresses always returns IP addresses as str
  • Loading branch information
devos50 committed Feb 23, 2017
2 parents d80b1c6 + 8463ae1 commit 8dd28a0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dispersy.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ def __repr__(self):
else:
for option in addresses.get(netifaces.AF_INET, []):
try:
yield Interface(interface, option.get("addr"), option.get("netmask"), option.get("broadcast"))
# On Windows netifaces currently returns IP addresses as unicode,
# and on *nix it returns str. So, we convert any unicode objects to str.
unicode_to_str = lambda s: s.encode('utf-8') if isinstance(s, unicode) else s
yield Interface(interface,
unicode_to_str(option.get("addr")),
unicode_to_str(option.get("netmask")),
unicode_to_str(option.get("broadcast")))

except TypeError:
# some interfaces have no netmask configured, causing a TypeError when
Expand Down

0 comments on commit 8dd28a0

Please sign in to comment.