MCPcopy
hub / github.com/urllib3/urllib3 / _new_conn

Method _new_conn

src/urllib3/connection.py:198–225  ·  view source on GitHub ↗

Establish a socket connection and set nodelay settings on it. :return: New socket connection.

(self)

Source from the content-addressed store, hash-verified

196 self._dns_host = value
197
198 def _new_conn(self) -> socket.socket:
199 """Establish a socket connection and set nodelay settings on it.
200
201 :return: New socket connection.
202 """
203 try:
204 sock = connection.create_connection(
205 (self._dns_host, self.port),
206 self.timeout,
207 source_address=self.source_address,
208 socket_options=self.socket_options,
209 )
210 except socket.gaierror as e:
211 raise NameResolutionError(self.host, self, e) from e
212 except SocketTimeout as e:
213 raise ConnectTimeoutError(
214 self,
215 f"Connection to {self.host} timed out. (connect timeout={self.timeout})",
216 ) from e
217
218 except OSError as e:
219 raise NewConnectionError(
220 self, f"Failed to establish a new connection: {e}"
221 ) from e
222
223 sys.audit("http.client.connect", self, self.host, self.port)
224
225 return sock
226
227 def set_tunnel(
228 self,

Calls 3

NameResolutionErrorClass · 0.85
ConnectTimeoutErrorClass · 0.85
NewConnectionErrorClass · 0.85