jonhadfield / python-hosts

a hosts file manager library written in python
MIT License
125 stars 33 forks source link

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

Closed HaHaHaHaIWin closed 2 years ago

HaHaHaHaIWin commented 2 years ago

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?

jonhadfield commented 2 years ago

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?

HaHaHaHaIWin commented 2 years ago

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!!!