[Win10] psutil.net_connections return mixed object types (namedtuple and tuple)
See original GitHub issuePlatform
- sys.getwindowsversion(major=6, minor=2, build=9200, platform=2, service_pack=‘’)
- ‘2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]’
- Version: 5.6.2
Bug description psutil.net_connections return mixed object types (namedtuple and tuple) I think it should be return type with namedtuple instead of tuple,or mixed types.
print [sconn.raddr for sconn in sconn_list if sconn.raddr.port == 993 and sconn.status == 'ESTABLISHED']
import psutil
sconn_list = psutil.net_connections(kind='tcp')
print sconn_list[0].raddr.port
print [type(sconn.raddr) for sconn in sconn_list]
print [sconn.raddr for sconn in sconn_list if sconn.raddr.port == 993 and sconn.status == 'ESTABLISHED']
Test results
Traceback (most recent call last):
File "C:/Users/Guodong/PycharmProjects/LinuxBashShellScriptForOps/functions/net/tcp/port/check-port-connection.py", line 33, in <module>
print [sconn.raddr for sconn in sconn_list if sconn.raddr.port == 993 and sconn.status == 'ESTABLISHED']
AttributeError: 'tuple' object has no attribute 'port'
thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
psutil.net_connections() should return namedtuple, but it is not ...
The documentation says: raddr : the remote address as a (ip, port) named tuple or an absolute path in case of UNIX sockets....
Read more >Write Pythonic and Clean Code With namedtuple - Real Python
With namedtuple() , you can create immutable sequence types that allow you to access their values using descriptive field names and the dot...
Read more >Namedtuple in Python - GeeksforGeeks
Python supports a type of container dictionaries called “namedtuple()” present in ... using ** operator to return namedtuple from dictionary.
Read more >NamedTuple class declaration for Python 3.6 not supported by ...
Pycharm doesn't recognize the type of the instance. Checked collection.namedtuple subclass, it's subclass shows no parameter info at all. (Doesn't complain like ...
Read more >Inheritance for Python Namedtuples - Zecong Hu's blog
Create a namedtuple class using _make_nmtuple . Note that the returned namedtuple class does not support default values or contain type ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hang on. =) If you see a tuple instead of namedtuple then it’s a bug.
😃, OK, you are so nice that I very appreciate it.
I am using this code to avoid this issue.
new code:
old code:
I think the location of
sconn.status == 'ESTABLISHED'
is key.Thanks~~~