Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'hop' referenced before assignment #1

Closed
rifen opened this issue Feb 19, 2020 · 1 comment
Closed

Comments

@rifen
Copy link

rifen commented Feb 19, 2020

Using your library I am having issues with the traceroute portion. Below is my code. I feel like I have practically followed your example besides using input instead of a pre-defined IP.

from icmplib import ping, multiping, traceroute, Host, Hop
def trace(addresses):
for address in addresses:
hops = traceroute(
"{address}", count=3, interval=0.5, timeout=2, max_hops=10, fast_mode=False,
)
print(address)
print("Distance (ttl) Address Average round-trip time")
last_distance = 0
for hop in hops:
if last_distance + 1 != hop.distance:
print("****")
print(f"{hop.distance} {hop.address} {hop.avg_rtt} ms")
last_distance = hop.distance

I am a beginner so maybe I am doing something wrong but it seems like hop isn't defined in your library.

@ValentinBELYN
Copy link
Owner

Hi, thank you for using my library 😃

The error you get may be related to an indentation error. Can you repost your indented code into a code block (or take a screenshot of your code)?
https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks

Otherwise, this line is incorrect:
hops = traceroute("{address}", count=3, interval=0.5, timeout=2, max_hops=10, fast_mode=False)

"{address}" is a string. It is not the address variable. Use instead:
hops = traceroute(address, count=3, interval=0.5, timeout=2, max_hops=10, fast_mode=False)

I hope this will help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants