Skip to content

Commit a2647e3

Browse files
committed
urllib.urequest: 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 2e4a29d commit a2647e3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

urllib.urequest/urllib/urequest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def urlopen(url, data=None, method="GET"):
2020
host, port = host.split(":", 1)
2121
port = int(port)
2222

23-
ai = usocket.getaddrinfo(host, port)
24-
addr = ai[0][4]
23+
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
24+
ai = ai[0]
2525

26-
s = usocket.socket()
26+
s = usocket.socket(ai[0], ai[1], ai[2])
2727
try:
28-
s.connect(addr)
28+
s.connect(ai[-1])
2929
if proto == "https:":
3030
s = ussl.wrap_socket(s, server_hostname=host)
3131

0 commit comments

Comments
 (0)