thombashi / pingparsing

pingparsing is a CLI-tool/Python-library parser and transmitter for ping command :arrow_right_hook:
https://pingparsing.rtfd.io/
MIT License
78 stars 10 forks source link

AttributeError: NoneType ... (example code not working) #32

Open laundmo opened 5 years ago

laundmo commented 5 years ago

hey there, im using a slightly modified version of the example library code

my code:

import json
import pingparsing

ping_parser = pingparsing.PingParsing()
transmitter = pingparsing.PingTransmitter()
transmitter.destination = "google.com"
transmitter.count = 1
result = transmitter.ping()
print("Pingparsing Result: \n")
print(result)
print("\njson.dumps: \n")
print(json.dumps(ping_parser.parse(result).as_dict(), indent=4))

and im getting a really weird result and then a NoneType error when trying to use the json.dumps....

Pingparsing Result:

PingResult(stdout='\xa0,ÈÑÎÁ\x80ä?ÀÁø/ÅÁ\x9a\x80\x94\x93\x04\x06\r\x8e\r\x8e&Ñ>Å\x80ÏÑÊÀ\x80/ÍËÅÁÃaÇÊÈ\x80ÃaÊ\x80Å??Å%Á\x06Ä?_\x80$\x16\x91\x96\x06\x95\x98\x06\x16\x91\x90\x06\x91\x94)\x80_ÑÈ\x80\x93\x16\x80â`ÈÁË\x80à/ÈÁ>\x9a\r\x8e\xa0>ÈÏ?ÊÈ\x80Î?>\x80\x16\x91\x96\x06\x95\x98\x06\x16\x91\x90\x06\x91\x94\x9a\x80â`ÈÁË\x15\x93\x16\x80!ÁÑÈ\x15\x16\x04_Ë\x80èè<\x15\x95\x96\r\x8e\r\x8e&Ñ>Å\x05ëÈ/ÈÑËÈÑ,\x80ÃaÊ\x80\x16\x91\x96\x06\x95\x98\x06\x16\x91\x90\x06\x91\x94\x9a\r\x8e\x80\x80\x80\x80&/,ÁÈÁ\x9a\x80åÁËÁ>ÀÁÈ\x80\x15\x80\x91\x8c\x80á_øÃ/>ÅÁ>\x80\x15\x80\x91\x8c\x80îÁÊ%?ÊÁ>\x80\x15\x80\x90\r\x8e\x80\x80\x80\x80\x88\x90\n\x80îÁÊ%ÍËÈ\x89\x8c\r\x8eä/\x06\x80!ÁÑÈ/>Å/ÂÁ>\x80Ñ>\x80(Ñ%%ÑËÁ,\x06\x9a\r\x8e\x80\x80\x80\x80(Ñ>Ñ_Í_\x80\x15\x80\x16\x04_Ë\x8c\x80(/ÌÑ_Í_\x80\x15\x80\x16\x04_Ë\x8c\x80(ÑÈÈÁ%ÏÁÊÈ\x80\x15\x80\x16\x04_Ë\r\x8e', stderr='', returncode=0)

json.dumps:

Traceback (most recent call last):
  File "c:/Users/lauri/python-projects/graph-ping/test.py", line 12, in <module>
    print(json.dumps(ping_parser.parse(result).as_dict(), indent=4))
AttributeError: 'NoneType' object has no attribute 'as_dict'

mind you, i get the same error when running the exact example from https://pingparsing.readthedocs.io/en/latest/pages/usage/library.html#execute-ping-and-parse-the-result

thombashi commented 5 years ago

Thank you for your report.

Probably the error caused by your locale setting. Your code and the example works fine with my environment (English locale). Please try to set your locale to English and re-execute.

laundmo commented 5 years ago

how do i set the locale? ivr tried all things i can think of, i even made a SuperUser thread asking, but nothing seems to work @thombashi

https://superuser.com/questions/1435601/change-cmd-language-permanently-to-english-windows10-specifically-ping-output

thombashi commented 5 years ago

chcp 437 would change the locale to English for my Windows environment. I am not so sure why that not works for your environment. How about chcp 65001 (UTF-8)?

laundmo commented 5 years ago

nope! still german..

thombashi commented 5 years ago

Thank you for confirmation.

I might possible to add German support in the future if you kindly provide me the following ping results:

1. Success case

Text version of your screenshot would be enough.

2. Failed case

Like the below, a ping result for an unknown destination:

Pinging 192.168.207.100 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 192.168.207.100:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
laundmo commented 5 years ago

success

Microsoft Windows [Version 10.0.17134.706]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>ping 1.1.1.1

Ping wird ausgeführt für 1.1.1.1 mit 32 Bytes Daten:
Antwort von 1.1.1.1: Bytes=32 Zeit=12ms TTL=59
Antwort von 1.1.1.1: Bytes=32 Zeit=12ms TTL=59
Antwort von 1.1.1.1: Bytes=32 Zeit=12ms TTL=59
Antwort von 1.1.1.1: Bytes=32 Zeit=12ms TTL=59

Ping-Statistik für 1.1.1.1:
    Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
    (0% Verlust),
Ca. Zeitangaben in Millisek.:
    Minimum = 12ms, Maximum = 12ms, Mittelwert = 12ms

C:\WINDOWS\system32>

failure

Microsoft Windows [Version 10.0.17134.706]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>ping 1.1.1.1

Ping wird ausgeführt für 1.1.1.1 mit 32 Bytes Daten:
Zeitüberschreitung der Anforderung.
Antwort von 192.168.178.1: Zielnetz nicht erreichbar.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.

Ping-Statistik für 1.1.1.1:
    Pakete: Gesendet = 4, Empfangen = 1, Verloren = 3
    (75% Verlust),

C:\WINDOWS\system32>

the failure was mostly timeout but in between there was a response with the message that the host couldn't be reached

thombashi commented 5 years ago

Thank you for your information. The enhancement might take some time.

Deretaz commented 3 years ago

any new information about german implemantation?

thombashi commented 3 years ago

This hasn't progressed much

piepero commented 1 year ago

Running into the same problem (also on a German Windows machine), I spent some time in the debugger to find the root of the problem, thinking it might be an easy fix. Here are some observations:

That's where I stopped and decided that for my purposes, a language agnostic ping library like ping3 or icmplib better fit the bill.