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
[Win10] psutil.net_connections return mixed object types (namedtuple and tuple) #1513
Comments
Besides, it can be fixed by using code as follows: import psutil
from psutil._common import addr # addr = namedtuple('addr', ['ip', 'port'])
sconn_list = psutil.net_connections(kind='tcp')
print sconn_list[0].raddr.port
print [sconn.raddr for sconn in sconn_list if
isinstance(sconn.raddr, addr) and sconn.raddr.port == 993 and sconn.status == 'ESTABLISHED'] |
Mmm... this is weird. I can't see anything in the code which justifies what you see. Could try try to debug with |
I'm sorry to make you confused, Maybe that's normal. item in import psutil
sconn_list = psutil.net_connections(kind='tcp')
for sconn in sconn_list:
print(type(sconn.raddr))
print(sconn) After I double check it, I think it is my own mistake, It will return tuple only when 'sconn.status='LISTEN'' Many thanks. ;) |
Hang on. =) |
:), OK, you are so nice that I very appreciate it. I am using this code to avoid this issue. new code: my_sconn_list = [sconn for sconn in sconn_list if sconn.status == 'ESTABLISHED' and sconn.raddr.port == port] old code: from psutil._common import addr
my_sconn_list = [sconn for sconn in sconn_list if
isinstance(sconn.raddr,
addr) and sconn.raddr.port == port and sconn.status == 'ESTABLISHED'] I think the location of Thanks~~~ |
Platform
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.
Test results
thanks.
The text was updated successfully, but these errors were encountered: