Skip to content

Commit 829f53d

Browse files
committed
urequests: 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 8392bd8 commit 829f53d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

urequests/urequests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def request(method, url, data=None, json=None, headers={}, stream=None):
5050
host, port = host.split(":", 1)
5151
port = int(port)
5252

53-
ai = usocket.getaddrinfo(host, port)
54-
addr = ai[0][-1]
53+
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
54+
ai = ai[0]
5555

56-
s = usocket.socket()
56+
s = usocket.socket(ai[0], ai[1], ai[2])
5757
try:
58-
s.connect(addr)
58+
s.connect(ai[-1])
5959
if proto == "https:":
6060
s = ussl.wrap_socket(s, server_hostname=host)
6161
s.write(b"%s /%s HTTP/1.0\r\n" % (method, path))

0 commit comments

Comments
 (0)