Reputation: 217
Am creating a python server socket from the return value os socket.getaddrinfo
which returns a sequence of 5-tuple (family, socktype, proto, canonname, sockaddr)
This is my code.
import socket
import collections
sock_info_tuple = namedtuple('sock_info_tuple', 'family type proto cannon sockaddr_tuple')
socket_info = sock_info_tuple._make(socket.getaddrinfo('127.0.0.1',80,socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_TCP))
TypeError Traceback (most recent call last)
<ipython-input-90-b04233a8e38d> in <module>()
5 #get the socket info
6 sock_info_tuple = namedtuple('sock_info_tuple', 'family type proto cannon sockaddr_tuple')
----> 7 socket_info = sock_info_tuple._make(socket.getaddrinfo('127.0.0.1',80,socket.AF_INET,socket .SOCK_STREAM,socket.IPPROTO_TCP))
8
9 #create the server scket and pass the arguments
<string> in _make(cls, iterable, new, len)
TypeError: Expected 5 arguments, got 1
so whats probably the problem and yet the socket.getaddrinfo returns the tuple
Upvotes: 0
Views: 98
Reputation: 2888
If socket.getaddrinfo
returns (family, socktype, proto, canonname, sockaddr)
as tuple, You should use *
to unpack this tuple.
socket_info = sock_info_tuple._make(*socket.getaddrinfo('127.0.0.1',80,socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_TCP))
Upvotes: 1