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

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

Open
laundmo opened this issue May 11, 2019 · 10 comments
Open

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

laundmo opened this issue May 11, 2019 · 10 comments
Assignees

Comments

@laundmo
Copy link

laundmo commented May 11, 2019

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

@laundmo laundmo changed the title example code not working AttributeError: NoneType ... (example code not working) May 11, 2019
@thombashi thombashi self-assigned this May 11, 2019
@thombashi
Copy link
Owner

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
Copy link
Author

laundmo commented May 11, 2019

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
Copy link
Owner

thombashi commented May 11, 2019

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
Copy link
Author

laundmo commented May 11, 2019

nope! still german..

@thombashi
Copy link
Owner

thombashi commented May 14, 2019

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
Copy link
Author

laundmo commented May 14, 2019

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
Copy link
Owner

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

@Deretaz
Copy link

Deretaz commented Apr 19, 2021

any new information about german implemantation?

@thombashi
Copy link
Owner

This hasn't progressed much

@piepero
Copy link

piepero commented Jan 13, 2023

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:

  • The garbled stoud text is a result of mbstrdecoder falsely assuming that the output of the ping command ist "utf-16". If __CODECS is modified so that "cp850" is above "utf-16", the conversion works as needed.
    mbstrdecord's strategy of decoding by iterating over a list of codecs is inherently flawed. It is almost guaranteed that a wrong codec will be used.
    It might be possible to get the right encoding by parsing the result of the chcp command (in my case, it returns Aktive Codepage: 850.).
  • After that workaround, there is still the matter of adapting the parser to a different language. A quick and dirty conversion from English to German got me pretty far, but for true multi language support, a more general (and flexible) solution would have to be implemented.

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

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

No branches or pull requests

4 participants