Hi, aside from the logic being incorrect, see the correction in this answer:
I believe what you're trying to achieve is the following:
def pingDomain(request, page): page_object = get_object_or_404(Table, page=page) try: subprocess.check_output(['ping', '-c', '1', page_object.page]) host_online = True except subprocess.CalledProcessError: host_online = False context = { 'online': host_online, } return render(request, 'home.html', context)
Reason being I've changed your logic is because if the…
I see a few additional problems:
some domains, even if online, won't respond to ICMP packets (what ping uses for the echo), which means that you'll have false negatives :)
ping
another bug in your logic is that it assumes that any type of response from ping, even unreachable domains, will result in the host marked online
I suggest you add a call to breakpoint() to the line before the subprocess call and check what's going on manually
breakpoint()
subprocess
Hey @rhymes ! Thanks! I'll check on this.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, aside from the logic being incorrect, see the correction in this answer:
answer re: Django view doesn't output correctly
I believe what you're trying to achieve is the following:
Reason being I've changed your logic is because if the…
I see a few additional problems:
some domains, even if online, won't respond to ICMP packets (what
ping
uses for the echo), which means that you'll have false negatives :)another bug in your logic is that it assumes that any type of response from ping, even unreachable domains, will result in the host marked online
I suggest you add a call to
breakpoint()
to the line before thesubprocess
call and check what's going on manuallyHey @rhymes ! Thanks! I'll check on this.