Skip to content

Commit 559d51c

Browse files
committed
upip: Be sure to create socket with params returned by getaddrinfo().
To use address as returned by getaddrinfo(), we should create a socket compatible with address family, etc., returned by the same call alongside the address itself.
1 parent f2114d8 commit 559d51c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

upip/upip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ def url_open(url):
117117

118118
proto, _, host, urlpath = url.split('/', 3)
119119
try:
120-
ai = usocket.getaddrinfo(host, 443)
120+
ai = usocket.getaddrinfo(host, 443, 0, usocket.SOCK_STREAM)
121121
except OSError as e:
122122
fatal("Unable to resolve %s (no Internet?)" % host, e)
123123
#print("Address infos:", ai)
124-
addr = ai[0][4]
124+
ai = ai[0]
125125

126-
s = usocket.socket(ai[0][0])
126+
s = usocket.socket(ai[0], ai[1], ai[2])
127127
try:
128128
#print("Connect address:", addr)
129-
s.connect(addr)
129+
s.connect(ai[-1])
130130

131131
if proto == "https:":
132132
s = ussl.wrap_socket(s, server_hostname=host)

0 commit comments

Comments
 (0)