From 682a66d1643ee99c38844c2c3c7ea8ba3dd3348d Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 25 Oct 2024 18:46:06 +0800 Subject: [PATCH] fix(tools/esp_prov): Fix hostname resolving for IPv6-only host --- tools/esp_prov/transport/transport_http.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/esp_prov/transport/transport_http.py b/tools/esp_prov/transport/transport_http.py index f17cfc8f6d..1474e4627f 100644 --- a/tools/esp_prov/transport/transport_http.py +++ b/tools/esp_prov/transport/transport_http.py @@ -1,8 +1,9 @@ -# SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 # import socket -from http.client import HTTPConnection, HTTPSConnection +from http.client import HTTPConnection +from http.client import HTTPSConnection from utils import str_to_bytes @@ -12,7 +13,7 @@ from .transport import Transport class Transport_HTTP(Transport): def __init__(self, hostname, ssl_context=None): try: - socket.gethostbyname(hostname.split(':')[0]) + socket.getaddrinfo(hostname.split(':')[0], None) except socket.gaierror: raise RuntimeError(f'Unable to resolve hostname: {hostname}') @@ -35,7 +36,7 @@ class Transport_HTTP(Transport): # While establishing a session, the device sends the Set-Cookie header # with value 'session=cookie_session_id' in its first response of the session to the tool. # To maintain the same session, successive requests from the tool should include - # an additional 'Cookie' header with the above recieved value. + # an additional 'Cookie' header with the above received value. for hdr_key, hdr_val in response.getheaders(): if hdr_key == 'Set-Cookie': self.headers['Cookie'] = hdr_val