jonhadfield/python-hosts

Exception: Address and Name(s) must be specified.

Closed this issue · 2 comments

It was actually working, i was in the process of adding a file read, when it quit working. Here is the code (the example from the manual)

from python_hosts import Hosts, HostsEntry
my_hosts = Hosts()
new_entry = HostsEntry(entry_type='ipv4', address='1.2.3.4', names=['example.com', 'example'])
my_hosts.add([new_entry])
my_hosts.write()
print(new_entry)

The execution and error

$ sudo python3 IPHostUpdate.py 1 ⨯
Traceback (most recent call last):
File "/home/kali/Desktop/IPHostUpdate.py", line 2, in
my_hosts = Hosts()
File "/usr/local/lib/python3.9/dist-packages/python_hosts/hosts.py", line 144, in init
self.populate_entries()
File "/usr/local/lib/python3.9/dist-packages/python_hosts/hosts.py", line 470, in populate_entries
HostsEntry(
File "/usr/local/lib/python3.9/dist-packages/python_hosts/hosts.py", line 54, in init
raise Exception('Address and Name(s) must be specified.')
Exception: Address and Name(s) must be specified.

I have uninstalled, and re-installed the app.

Any thoughts?

Hi @HaHaHaHaIWin, The error suggests it failed to load your existing hosts file as it found an entry without both IP and name. Does that apply in this case?

That was it.

seems as if it is pulling in a hard return from my file of ip addresses and breaking the line

Thank you!!!