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

Destination unreachible causes AttributeError in DestinationUnreachible #52

Closed
drisen opened this issue Mar 30, 2022 · 5 comments
Closed

Comments

@drisen
Copy link

drisen commented Mar 30, 2022

In Windows 10, Python 3.8, ping version 4.0.0, using WiFi access to the network: if the laptop's WiFi disconnects, ping3.ping detects that the destination is unreachable, but then dies processing the error with an AttributeError in class DestinationUnreachable. E.g.

Traceback (most recent call last):
File "G:/My Drive/Case/PyCharm/netstats/ping_stats.py", line 47, in
result = ping3.ping(site.ipAddress, timeout=timeout, unit='ms', size=56)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 83, in wrapper
func_return = func(*args, **kwargs)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 311, in ping
delay = receive_one_ping(sock=sock, icmp_id=icmp_id, seq=seq, timeout=timeout) # in seconds
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 83, in wrapper
func_return = func(*args, **kwargs)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 240, in receive_one_ping
raise errors.DestinationHostUnreachable(ip_header=ip_header, icmp_header=icmp_header)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3\errors.py", line 30, in init
super().init(self.message)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3\errors.py", line 21, in init
self.message = message if self.ip_header is None else message + " (Host='{}')".format(self.ip_header.get("src_addr"))
AttributeError: 'str' object has no attribute 'get'

@kyan001
Copy link
Owner

kyan001 commented Mar 30, 2022

Hi @drisen ,

Sorry for the inconvenience. I'll look into the bug. Is it possible to have the debug outputs for such a case? Just turn on ping3.DEBUG = True right after import ping3. It would be a great help to address the problem.

Thanks.

@drisen
Copy link
Author

drisen commented Mar 30, 2022 via email

@canepan
Copy link
Contributor

canepan commented Apr 8, 2022

Hi, I noticed the same under Linux.
No output change even with ping3.DEBUG = True:

Traceback (most recent call last):
  File "/etc/keepalived/bin/status.py", line 501, in <module>
    sys.exit(main())
  File "/etc/keepalived/bin/status.py", line 482, in main
    if rstatus.reachable:
  File "/etc/keepalived/bin/status.py", line 307, in reachable
    if failback_ping(self.rhost, port=22):
  File "/etc/keepalived/bin/net_utils.py", line 16, in failback_ping
    return ping(*args, **kwargs)
  File "/mnt/opt/nicola/tools/lib/python3.7/site-packages/ping3/__init__.py", line 83, in wrapper
    func_return = func(*args, **kwargs)
  File "/mnt/opt/nicola/tools/lib/python3.7/site-packages/ping3/__init__.py", line 311, in ping
    delay = receive_one_ping(sock=sock, icmp_id=icmp_id, seq=seq, timeout=timeout)  # in seconds
  File "/mnt/opt/nicola/tools/lib/python3.7/site-packages/ping3/__init__.py", line 83, in wrapper
    func_return = func(*args, **kwargs)
  File "/mnt/opt/nicola/tools/lib/python3.7/site-packages/ping3/__init__.py", line 240, in receive_one_ping
    raise errors.DestinationHostUnreachable(ip_header=ip_header, icmp_header=icmp_header)
  File "/mnt/opt/nicola/tools/lib/python3.7/site-packages/ping3/errors.py", line 30, in __init__
    super().__init__(self.message)
  File "/mnt/opt/nicola/tools/lib/python3.7/site-packages/ping3/errors.py", line 21, in __init__
    self.message = message if self.ip_header is None else message + " (Host='{}')".format(self.ip_header.get("src_addr"))
AttributeError: 'str' object has no attribute 'get'

This is the content of self.ip_header:

Destination unreachable: Host unreachable. (Host='X.X.X.X')

where X.X.X.X is my IP address

@canepan
Copy link
Contributor

canepan commented Apr 8, 2022

I think it can be resolved by changing line 30 (and possibly the same lines doing the same) with:

    super().__init__(message=self.message)

@drisen
Copy link
Author

drisen commented Oct 11, 2022 via email

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

3 participants